1 #!/bin/bash 2 # 3 # Copyright 2018 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # make us exit on a failure 18 set -e 19 20 ASM_JAR="${ANDROID_BUILD_TOP}/prebuilts/misc/common/asm/asm-6.0.jar" 21 INTERMEDIATE_CLASSES=classes-intermediate 22 CLASSES=classes 23 24 DEXER="${DX:-dx}" 25 if [ "${USE_D8=false}" = "true" ]; then 26 DEXER="${ANDROID_HOST_OUT}/bin/d8-compat-dx" 27 fi 28 29 # Create directory for intermediate classes 30 rm -rf "${INTERMEDIATE_CLASSES}" 31 mkdir "${INTERMEDIATE_CLASSES}" 32 33 # Generate intermediate classes that will allow transform to be applied to test classes 34 JAVAC_ARGS="${JAVAC_ARGS} -source 1.8 -target 1.8 -cp ${ASM_JAR}" 35 ${JAVAC:-javac} ${JAVAC_ARGS} -d ${INTERMEDIATE_CLASSES} $(find src -name '*.java') 36 37 # Create directory for transformed classes 38 rm -rf "${CLASSES}" 39 mkdir "${CLASSES}" 40 41 # Run transform 42 for class in ${INTERMEDIATE_CLASSES}/*.class ; do 43 transformed_class=${CLASSES}/$(basename ${class}) 44 ${JAVA:-java} -cp "${ASM_JAR}:${INTERMEDIATE_CLASSES}" transformer.IndyTransformer ${class} ${transformed_class} 45 done 46 47 # Create DEX 48 DX_FLAGS="${DX_FLAGS} --min-sdk-version=26 --debug --dump-width=1000" 49 ${DEXER} -JXmx256m --dex ${DX_FLAGS} --dump-to=${CLASSES}.lst --output=classes.dex ${CLASSES} 50 51 # Zip DEX to file name expected by test runner 52 zip ${TEST_NAME:-classes-dex}.jar classes.dex 53