Android O SDK.
[android_tools.git] / sdk / build-tools / 26.0.0 / mainDexClasses
blobd1b0a2c32b7418ecaa96e1e555c0b702cecfdb24
1 #!/bin/bash
3 # Copyright (C) 2013 The Android Open Source Project
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 function makeTempJar ()
19 local tempDir=/tmp
20 if [ ! -e "${tempDir}" ]; then
21 tempDir=.
23 local tempfile="${tempDir}/mainDexClasses-$$.tmp.jar"
24 if [ -e "${tempfile}" ]; then
25 echo "Failed to create temporary file" >2
26 exit 6
28 echo "${tempfile}"
31 function cleanTmp ()
33 if [ -e "${tmpOut}" ] ; then
34 rm "${tmpOut}"
39 # Set up prog to be the path of this script, including following symlinks,
40 # and set up progdir to be the fully-qualified pathname of its directory.
41 prog="$0"
43 while [ -h "${prog}" ]; do
44 newProg=`/bin/ls -ld "${prog}"`
45 newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
46 if expr "x${newProg}" : 'x/' >/dev/null; then
47 prog="${newProg}"
48 else
49 progdir=`dirname "${prog}"`
50 prog="${progdir}/${newProg}"
52 done
53 oldwd=`pwd`
54 progdir=`dirname "${prog}"`
55 cd "${progdir}"
56 progdir=`pwd`
57 prog="${progdir}"/`basename "${prog}"`
58 cd "${oldwd}"
60 baserules="${progdir}"/mainDexClasses.rules
61 if [ ! -r ${baserules} ]; then
62 echo `basename "$prog"`": can't find mainDexClasses.rules" 1>&2
63 exit 1
66 extrarules="${progdir}"/mainDexClassesNoAapt.rules
67 if [ ! -r ${extrarules} ]; then
68 echo `basename "$prog"`": can't find mainDexClassesNoAapt.rules" 1>&2
69 exit 1
72 jarfile=dx.jar
73 libdir="$progdir"
75 if [ ! -r "$libdir/$jarfile" ]; then
76 # set dx.jar location for the SDK case
77 libdir="$libdir/lib"
81 if [ ! -r "$libdir/$jarfile" ]; then
82 # set dx.jar location for the Android tree case
83 libdir=`dirname "$progdir"`/framework
86 if [ ! -r "$libdir/$jarfile" ]; then
87 echo `basename "$prog"`": can't find $jarfile" 1>&2
88 exit 1
91 proguardExec="proguard.sh"
92 proguard=${PROGUARD_HOME}/bin/${proguardExec}
94 if [ ! -r "${proguard}" ]; then
95 # set proguard location for the SDK case
96 proguardBaseDir=`dirname "$progdir"`
97 # "${progdir}"/../..
98 proguardBaseDir=`dirname "$proguardBaseDir"`
99 proguard="${proguardBaseDir}"/tools/proguard/bin/${proguardExec}
102 if [ ! -r "${proguard}" ]; then
103 # set proguard location for the Android tree case
104 proguardBaseDir=`dirname "$proguardBaseDir"`
105 # "${progdir}"/../../../..
106 proguardBaseDir=`dirname "$proguardBaseDir"`
107 proguard="${proguardBaseDir}"/external/proguard/bin/${proguardExec}
110 if [ ! -r "${proguard}" ]; then
111 proguard="${ANDROID_BUILD_TOP}"/external/proguard/bin/${proguardExec}
114 if [ ! -r "${proguard}" ]; then
115 proguard="`which proguard`"
118 if [ -z "${proguard}" -o ! -r "${proguard}" ]; then
119 proguard="`which ${proguardExec}`"
122 if [ -z "${proguard}" -o ! -r "${proguard}" ]; then
123 echo `basename "$prog"`": can't find ${proguardExec}" 1>&2
124 exit 1
127 shrinkedAndroidJar="${SHRINKED_ANDROID_JAR}"
128 if [ -z "${shrinkedAndroidJar}" ]; then
129 shrinkedAndroidJar=shrinkedAndroid.jar
132 if [ ! -r "${shrinkedAndroidJar}" ]; then
133 shrinkedAndroidJar=${libdir}/${shrinkedAndroidJar}
136 if [ ! -r "${shrinkedAndroidJar}" ]; then
137 echo `basename "$prog"`": can't find shrinkedAndroid.jar" 1>&2
138 exit 1
141 if [ "$OSTYPE" = "cygwin" ]; then
142 # For Cygwin, convert the jarfile path into native Windows style.
143 jarpath=`cygpath -w "$libdir/$jarfile"`
144 proguard=`cygpath -w "${proguard}"`
145 shrinkedAndroidJar=`cygpath -w "${shrinkedAndroidJar}"`
146 else
147 jarpath="$libdir/$jarfile"
150 disableKeepAnnotated=
152 while true; do
153 if expr "x$1" : 'x--output' >/dev/null; then
154 exec 1>$2
155 shift 2
156 elif expr "x$1" : 'x--disable-annotation-resolution-workaround' >/dev/null; then
157 disableKeepAnnotated=$1
158 shift 1
159 elif expr "x$1" : "x--aapt-rules" >/dev/null; then
160 extrarules=$2
161 shift 2
162 else
163 break
165 done
167 if [ $# -ne 1 ]; then
168 echo "Usage : $0 [--output <output file>] <application path>" 1>&2
169 exit 2
172 tmpOut=`makeTempJar`
174 trap cleanTmp 0
176 ${proguard} -injars ${@} -dontwarn -forceprocessing -outjars ${tmpOut} \
177 -libraryjars "${shrinkedAndroidJar}" -dontoptimize -dontobfuscate -dontpreverify \
178 -include "${baserules}" -include "${extrarules}" 1>/dev/null || exit 10
180 java -cp "$jarpath" com.android.multidex.MainDexListBuilder ${disableKeepAnnotated} "${tmpOut}" ${@} || exit 11