blob: 92954a98cc0e4f124a292b334d12ac552ffb1e25 [file] [log] [blame]
jeffhao5d1ac922011-09-29 17:41:15 -07001#!/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.
18set -e
19
David Brazdil4846d132015-01-15 19:07:08 +000020DX_FLAGS=""
Igor Murashkin158f35c2015-06-10 15:55:30 -070021SKIP_DX_MERGER="false"
David Brazdil4846d132015-01-15 19:07:08 +000022
23while 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
35done
36
Stephen Kyle40d35182014-10-03 13:47:56 +010037if [ -e classes.dex ]; then
38 zip $TEST_NAME.jar classes.dex
39 exit 0
40fi
41
Igor Murashkin158f35c2015-06-10 15:55:30 -070042if [ -d src ]; then
43 mkdir classes
44 ${JAVAC} -implicit:none -classpath src-multidex -d classes `find src -name '*.java'`
45fi
jeffhao5d1ac922011-09-29 17:41:15 -070046
Roland Levillain560b5ac2014-10-23 16:40:59 +010047if [ -d src2 ]; then
Igor Murashkin158f35c2015-06-10 15:55:30 -070048 mkdir -p classes
Elliott Hughesc717eef2012-06-15 16:01:26 -070049 ${JAVAC} -d classes `find src2 -name '*.java'`
jeffhao5d1ac922011-09-29 17:41:15 -070050fi
51
Igor Murashkin158f35c2015-06-10 15:55:30 -070052if ! [ -d src ] && ! [ -d src2 ]; then
53 # No src directory? Then forget about trying to run dx.
54 SKIP_DX_MERGER="true"
55fi
56
57if [ ${NEED_DEX} = "true" -a ${SKIP_DX_MERGER} = "false" ]; then
David Brazdil4846d132015-01-15 19:07:08 +000058 ${DX} -JXmx256m --debug --dex --dump-to=classes.lst --output=classes.dex \
59 --dump-width=1000 ${DX_FLAGS} classes
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010060fi
61
Roland Levillain560b5ac2014-10-23 16:40:59 +010062if [ -d smali ]; then
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010063 # Compile Smali classes
Igor Murashkin158f35c2015-06-10 15:55:30 -070064 ${SMALI} -JXmx256m --experimental --api-level 23 --output smali_classes.dex `find smali -name '*.smali'`
65
66 # Don't bother with dexmerger if we provide our own main function in a smali file.
67 if [ ${SKIP_DX_MERGER} = "false" ]; then
68 ${DXMERGER} classes.dex classes.dex smali_classes.dex
69 else
70 mv smali_classes.dex classes.dex
71 fi
Elliott Hughesc717eef2012-06-15 16:01:26 -070072fi
TDYa127b92bcab2012-04-08 00:09:51 -070073
Roland Levillain560b5ac2014-10-23 16:40:59 +010074if [ -d src-ex ]; then
Elliott Hughesc717eef2012-06-15 16:01:26 -070075 mkdir classes-ex
76 ${JAVAC} -d classes-ex -cp classes `find src-ex -name '*.java'`
77 if [ ${NEED_DEX} = "true" ]; then
David Brazdil4846d132015-01-15 19:07:08 +000078 ${DX} -JXmx256m --debug --dex --dump-to=classes-ex.lst --output=classes-ex.dex \
79 --dump-width=1000 ${DX_FLAGS} classes-ex
jeffhao5d1ac922011-09-29 17:41:15 -070080
81 # quick shuffle so that the stored name is "classes.dex"
82 mv classes.dex classes-1.dex
83 mv classes-ex.dex classes.dex
Brian Carlstrom904667a2012-03-10 23:43:07 -080084 zip $TEST_NAME-ex.jar classes.dex
jeffhao5d1ac922011-09-29 17:41:15 -070085 mv classes.dex classes-ex.dex
86 mv classes-1.dex classes.dex
Elliott Hughesc717eef2012-06-15 16:01:26 -070087 fi
jeffhao5d1ac922011-09-29 17:41:15 -070088fi
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +010089
Nicolas Geoffray9437b782015-03-25 10:08:51 +000090# Create a single jar with two dex files for multidex.
91if [ -d src-multidex ]; then
92 mkdir classes2
93 ${JAVAC} -implicit:none -classpath src -d classes2 `find src-multidex -name '*.java'`
94 if [ ${NEED_DEX} = "true" ]; then
95 ${DX} -JXmx256m --debug --dex --dump-to=classes2.lst --output=classes2.dex \
96 --dump-width=1000 ${DX_FLAGS} classes2
97 zip $TEST_NAME.jar classes.dex classes2.dex
98 fi
99elif [ ${NEED_DEX} = "true" ]; then
Nicolas Geoffray12508612014-11-05 12:34:24 +0000100 zip $TEST_NAME.jar classes.dex
101fi