1@echo off 2REM Copyright (C) 2013 The Android Open Source Project 3REM 4REM Licensed under the Apache License, Version 2.0 (the "License"); 5REM you may not use this file except in compliance with the License. 6REM You may obtain a copy of the License at 7REM 8REM http://www.apache.org/licenses/LICENSE-2.0 9REM 10REM Unless required by applicable law or agreed to in writing, software 11REM distributed under the License is distributed on an "AS IS" BASIS, 12REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13REM See the License for the specific language governing permissions and 14REM limitations under the License. 15 16REM don't modify the caller's environment 17setlocal 18 19rem Check we have a valid Java.exe in the path. 20set java_exe= 21if exist "%~dp0..\tools\lib\find_java.bat" call "%~dp0..\tools\lib\find_java.bat" 22if exist "%~dp0..\..\tools\lib\find_java.bat" call "%~dp0..\..\tools\lib\find_java.bat" 23if not defined java_exe goto :EOF 24 25set baserules="%~dp0\mainDexClasses.rules" 26set extrarules="%~dp0\mainDexClassesNoAapt.rules" 27 28REM Locate dx.jar in the directory where dx.bat was found. 29set jarfile=dx.jar 30set "frameworkdir=%~dp0" 31rem frameworkdir must not end with a dir sep. 32set "frameworkdir=%frameworkdir:~0,-1%" 33if exist "%frameworkdir%\%jarfile%" goto JarFileOk 34 set "frameworkdir=%~dp0lib" 35 36if exist "%frameworkdir%\%jarfile%" goto JarFileOk 37 set "frameworkdir=%~dp0..\framework" 38:JarFileOk 39 40set "jarpath=%frameworkdir%\%jarfile%" 41 42set "shrinkedAndroidJar=%SHRINKED_ANDROID_JAR% 43if exist "%shrinkedAndroidJar%" goto shrinkedAndroidOk 44 set "shrinkedAndroidJar=shrinkedAndroid.jar" 45 46if exist "%shrinkedAndroidJar%" goto shrinkedAndroidOk 47 set "shrinkedAndroidJar=%frameworkdir%\%shrinkedAndroidJar%" 48 49:shrinkedAndroidOk 50set "proguardExec=proguard.bat" 51set "proguard=%PROGUARD_HOME%\bin\%proguardExec%" 52 53if exist "%proguard%" goto proguardOk 54REM set proguard location for the SDK case 55 set "PROGUARD_HOME=%~dp0\..\..\tools\proguard" 56 set "proguard=%PROGUARD_HOME%\bin\%proguardExec%" 57 58if exist "%proguard%" goto proguardOk 59REM set proguard location for the Android tree case 60 set "PROGUARD_HOME=%~dp0\..\..\..\..\external\proguard" 61 set "proguard=%PROGUARD_HOME%\bin\%proguardExec%" 62 63:proguardOk 64REM Capture all arguments. 65REM Note that when reading the input arguments with %1, the cmd.exe 66REM automagically converts --name=value arguments into 2 arguments "--name" 67REM followed by "value". Dx has been changed to know how to deal with that. 68set params= 69 70set output= 71set disableKeepAnnotated= 72 73:firstArg 74if [%1]==[] goto endArgs 75 76 if %1 NEQ --output goto notOut 77 set "output=%2" 78 shift 79 shift 80 goto firstArg 81 82:notOut 83 84 if %1 NEQ --disable-annotation-resolution-workaround goto notDisable 85 set "disableKeepAnnotated=%1" 86 shift 87 goto firstArg 88 89:notDisable 90 91 if %1 NEQ --aapt-rules goto notAapt 92 set "extrarules=%2" 93 shift 94 shift 95 goto firstArg 96 97:notAapt 98 if defined params goto usage 99 set params=%1 100 shift 101 goto firstArg 102 103:endArgs 104if defined params ( goto makeTmpJar ) else ( goto usage ) 105 106:makeTmpJar 107set "tmpJar=%TMP%\mainDexClasses-%RANDOM%.tmp.jar" 108if exist "%tmpJar%" goto makeTmpJar 109echo "" > "%tmpJar%" 110set "exitStatus=0" 111 112 113call "%proguard%" -injars %params% -dontwarn -forceprocessing -outjars "%tmpJar%" -libraryjars "%shrinkedAndroidJar%" -dontoptimize -dontobfuscate -dontpreverify -include "%baserules%" -include "%extrarules%" 1>nul 114 115if DEFINED output goto redirect 116call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder %disableKeepAnnotated% "%tmpJar%" "%params%" 117goto afterClassReferenceListBuilder 118:redirect 119call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder %disableKeepAnnotated% "%tmpJar%" "%params%" 1>"%output%" 120:afterClassReferenceListBuilder 121 122del %tmpJar% 123exit /b 124 125:usage 126echo "Usage : %0 [--output <output file>] <application path>" 127exit /b 1 128