jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 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 | |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 20 | DX_FLAGS="" |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 21 | SKIP_DX_MERGER="false" |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 22 | |
| 23 | while true; do |
| 24 | if [ "x$1" = "x--dx-option" ]; then |
| 25 | shift |
| 26 | option="$1" |
| 27 | DX_FLAGS="${DX_FLAGS} $option" |
| 28 | shift |
| 29 | elif expr "x$1" : "x--" >/dev/null 2>&1; then |
| 30 | echo "unknown $0 option: $1" 1>&2 |
| 31 | exit 1 |
| 32 | else |
| 33 | break |
| 34 | fi |
| 35 | done |
| 36 | |
Stephen Kyle | 40d3518 | 2014-10-03 13:47:56 +0100 | [diff] [blame] | 37 | if [ -e classes.dex ]; then |
| 38 | zip $TEST_NAME.jar classes.dex |
| 39 | exit 0 |
| 40 | fi |
| 41 | |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 42 | if ! [ -d src ] && ! [ -d src2 ]; then |
| 43 | # No src directory? Then forget about trying to run dx. |
| 44 | SKIP_DX_MERGER="true" |
| 45 | fi |
| 46 | |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame^] | 47 | if [ -d src-multidex ]; then |
| 48 | # Jack does not support this configuration unless we specify how to partition the DEX file |
| 49 | # with a .jpp file. |
| 50 | USE_JACK="false" |
| 51 | fi |
| 52 | |
| 53 | if [ ${USE_JACK} = "true" ]; then |
| 54 | # Jack toolchain |
| 55 | if [ -d src ]; then |
| 56 | ${JACK} --output-jack src.jack src |
| 57 | imported_jack_files="--import src.jack" |
| 58 | fi |
| 59 | |
| 60 | if [ -d src2 ]; then |
| 61 | ${JACK} --output-jack src2.jack src2 |
| 62 | imported_jack_files="--import src2.jack ${imported_jack_files}" |
| 63 | fi |
| 64 | |
| 65 | # Compile jack files into a DEX file. We set jack.import.type.policy=keep-first to consider |
| 66 | # class definitions from src2 first. |
| 67 | ${JACK} ${imported_jack_files} -D jack.import.type.policy=keep-first --output-dex . |
| 68 | else |
| 69 | # Legacy toolchain with javac+dx |
| 70 | if [ -d src ]; then |
| 71 | mkdir classes |
| 72 | ${JAVAC} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'` |
| 73 | fi |
| 74 | |
| 75 | if [ -d src-multidex ]; then |
| 76 | mkdir classes2 |
| 77 | ${JAVAC} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'` |
| 78 | if [ ${NEED_DEX} = "true" ]; then |
| 79 | ${DX} -JXmx256m --debug --dex --dump-to=classes2.lst --output=classes2.dex \ |
| 80 | --dump-width=1000 ${DX_FLAGS} classes2 |
| 81 | fi |
| 82 | fi |
| 83 | |
| 84 | if [ -d src2 ]; then |
| 85 | mkdir -p classes |
| 86 | ${JAVAC} -d classes `find src2 -name '*.java'` |
| 87 | fi |
| 88 | |
| 89 | if [ ${NEED_DEX} = "true" -a ${SKIP_DX_MERGER} = "false" ]; then |
| 90 | ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex \ |
| 91 | --dump-width=1000 ${DX_FLAGS} classes |
| 92 | fi |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 93 | fi |
| 94 | |
Roland Levillain | 560b5ac | 2014-10-23 16:40:59 +0100 | [diff] [blame] | 95 | if [ -d smali ]; then |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 96 | # Compile Smali classes |
Igor Murashkin | 158f35c | 2015-06-10 15:55:30 -0700 | [diff] [blame] | 97 | ${SMALI} -JXmx256m --experimental --api-level 23 --output smali_classes.dex `find smali -name '*.smali'` |
| 98 | |
| 99 | # Don't bother with dexmerger if we provide our own main function in a smali file. |
| 100 | if [ ${SKIP_DX_MERGER} = "false" ]; then |
| 101 | ${DXMERGER} classes.dex classes.dex smali_classes.dex |
| 102 | else |
| 103 | mv smali_classes.dex classes.dex |
| 104 | fi |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 105 | fi |
TDYa127 | b92bcab | 2012-04-08 00:09:51 -0700 | [diff] [blame] | 106 | |
Roland Levillain | 560b5ac | 2014-10-23 16:40:59 +0100 | [diff] [blame] | 107 | if [ -d src-ex ]; then |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame^] | 108 | if [ ${USE_JACK} = "true" ]; then |
| 109 | # Rename previous "classes.dex" so it is not overwritten. |
| 110 | mv classes.dex classes-1.dex |
| 111 | #TODO find another way to append src.jack to the jack classpath |
| 112 | ${JACK}:src.jack --output-dex . src-ex |
| 113 | zip $TEST_NAME-ex.jar classes.dex |
| 114 | # Restore previous "classes.dex" so it can be zipped. |
| 115 | mv classes-1.dex classes.dex |
| 116 | else |
| 117 | mkdir classes-ex |
| 118 | ${JAVAC} -d classes-ex -cp classes `find src-ex -name '*.java'` |
| 119 | if [ ${NEED_DEX} = "true" ]; then |
| 120 | ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \ |
| 121 | --dump-width=1000 ${DX_FLAGS} classes-ex |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 122 | |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame^] | 123 | # quick shuffle so that the stored name is "classes.dex" |
| 124 | mv classes.dex classes-1.dex |
| 125 | mv classes-ex.dex classes.dex |
| 126 | zip $TEST_NAME-ex.jar classes.dex |
| 127 | mv classes.dex classes-ex.dex |
| 128 | mv classes-1.dex classes.dex |
| 129 | fi |
Elliott Hughes | c717eef | 2012-06-15 16:01:26 -0700 | [diff] [blame] | 130 | fi |
jeffhao | 5d1ac92 | 2011-09-29 17:41:15 -0700 | [diff] [blame] | 131 | fi |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 132 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 133 | # Create a single jar with two dex files for multidex. |
| 134 | if [ -d src-multidex ]; then |
Sebastien Hertz | 19ac027 | 2015-02-24 17:39:50 +0100 | [diff] [blame^] | 135 | zip $TEST_NAME.jar classes.dex classes2.dex |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 136 | elif [ ${NEED_DEX} = "true" ]; then |
Nicolas Geoffray | 1250861 | 2014-11-05 12:34:24 +0000 | [diff] [blame] | 137 | zip $TEST_NAME.jar classes.dex |
| 138 | fi |