1 #!/bin/bash 2 # 3 # Copyright (C) 2008 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 # Stop if something fails. 18 set -e 19 20 DX_FLAGS="" 21 22 while true; do 23 if [ "x$1" = "x--dx-option" ]; then 24 shift 25 option="$1" 26 DX_FLAGS="${DX_FLAGS} $option" 27 shift 28 elif expr "x$1" : "x--" >/dev/null 2>&1; then 29 echo "unknown $0 option: $1" 1>&2 30 exit 1 31 else 32 break 33 fi 34 done 35 36 if [ -e classes.dex ]; then 37 zip $TEST_NAME.jar classes.dex 38 exit 0 39 fi 40 41 if [ -d src-multidex ]; then 42 # Jack does not support this configuration unless we specify how to partition the DEX file 43 # with a .jpp file. 44 USE_JACK="false" 45 fi 46 47 if [ ${USE_JACK} = "true" ]; then 48 # Jack toolchain 49 if [ -d src ]; then 50 ${JACK} --output-jack src.jack src 51 imported_jack_files="--import src.jack" 52 fi 53 54 if [ -d src2 ]; then 55 ${JACK} --output-jack src2.jack src2 56 imported_jack_files="--import src2.jack ${imported_jack_files}" 57 fi 58 59 # Compile jack files into a DEX file. We set jack.import.type.policy=keep-first to consider 60 # class definitions from src2 first. 61 ${JACK} ${imported_jack_files} -D jack.import.type.policy=keep-first --output-dex . 62 else 63 # Legacy toolchain with javac+dx 64 if [ -d src ]; then 65 mkdir classes 66 ${JAVAC} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'` 67 fi 68 69 if [ -d src-multidex ]; then 70 mkdir classes2 71 ${JAVAC} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'` 72 if [ ${NEED_DEX} = "true" ]; then 73 ${DX} -JXmx256m --debug --dex --dump-to=classes2.lst --output=classes2.dex \ 74 --dump-width=1000 ${DX_FLAGS} classes2 75 fi 76 fi 77 78 if [ -d src2 ]; then 79 mkdir -p classes 80 ${JAVAC} -d classes `find src2 -name '*.java'` 81 fi 82 83 if [ ${NEED_DEX} = "true" ]; then 84 ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex \ 85 --dump-width=1000 ${DX_FLAGS} classes 86 fi 87 fi 88 89 if [ -d smali ]; then 90 # Compile Smali classes 91 ${SMALI} -JXmx256m --output smali_classes.dex `find smali -name '*.smali'` 92 ${DXMERGER} classes.dex classes.dex smali_classes.dex 93 fi 94 95 if [ -d src-ex ]; then 96 if [ ${USE_JACK} = "true" ]; then 97 # Rename previous "classes.dex" so it is not overwritten. 98 mv classes.dex classes-1.dex 99 #TODO find another way to append src.jack to the jack classpath 100 ${JACK}:src.jack --output-dex . src-ex 101 zip $TEST_NAME-ex.jar classes.dex 102 # Restore previous "classes.dex" so it can be zipped. 103 mv classes-1.dex classes.dex 104 else 105 mkdir classes-ex 106 ${JAVAC} -d classes-ex -cp classes `find src-ex -name '*.java'` 107 if [ ${NEED_DEX} = "true" ]; then 108 ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \ 109 --dump-width=1000 ${DX_FLAGS} classes-ex 110 111 # quick shuffle so that the stored name is "classes.dex" 112 mv classes.dex classes-1.dex 113 mv classes-ex.dex classes.dex 114 zip $TEST_NAME-ex.jar classes.dex 115 mv classes.dex classes-ex.dex 116 mv classes-1.dex classes.dex 117 fi 118 fi 119 fi 120 121 # Create a single jar with two dex files for multidex. 122 if [ -d src-multidex ]; then 123 zip $TEST_NAME.jar classes.dex classes2.dex 124 elif [ ${NEED_DEX} = "true" ]; then 125 zip $TEST_NAME.jar classes.dex 126 fi 127