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 19@rem Find java.exe 20if defined JAVA_HOME goto findJavaFromJavaHome 21 22set JAVA_EXE=java.exe 23%JAVA_EXE% -version >NUL 2>&1 24if "%ERRORLEVEL%" == "0" goto init 25 26echo. 27echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28echo. 29echo Please set the JAVA_HOME variable in your environment to match the 30echo location of your Java installation. 31exit /b 1 32 33:findJavaFromJavaHome 34set JAVA_HOME=%JAVA_HOME:"=% 35set JAVA_EXE=%JAVA_HOME%/bin/java.exe 36 37if exist "%JAVA_EXE%" goto init 38 39echo. 40echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 41echo. 42echo Please set the JAVA_HOME variable in your environment to match the 43echo location of your Java installation. 44exit /b 1 45 46:init 47set baserules="%~dp0\mainDexClasses.rules" 48set extrarules="%~dp0\mainDexClassesNoAapt.rules" 49 50REM Locate dx.jar in the directory where dx.bat was found. 51set jarfile=dx.jar 52set "frameworkdir=%~dp0" 53rem frameworkdir must not end with a dir sep. 54set "frameworkdir=%frameworkdir:~0,-1%" 55if exist "%frameworkdir%\%jarfile%" goto JarFileOk 56 set "frameworkdir=%~dp0lib" 57 58if exist "%frameworkdir%\%jarfile%" goto JarFileOk 59 set "frameworkdir=%~dp0..\framework" 60:JarFileOk 61 62set "jarpath=%frameworkdir%\%jarfile%" 63 64set "shrinkedAndroidJar=%SHRINKED_ANDROID_JAR% 65if exist "%shrinkedAndroidJar%" goto shrinkedAndroidOk 66 set "shrinkedAndroidJar=shrinkedAndroid.jar" 67 68if exist "%shrinkedAndroidJar%" goto shrinkedAndroidOk 69 set "shrinkedAndroidJar=%frameworkdir%\%shrinkedAndroidJar%" 70 71:shrinkedAndroidOk 72set "proguardExec=proguard.bat" 73set "proguard=%PROGUARD_HOME%\bin\%proguardExec%" 74 75if exist "%proguard%" goto proguardOk 76REM set proguard location for the SDK case 77 set "PROGUARD_HOME=%~dp0\..\..\tools\proguard" 78 set "proguard=%PROGUARD_HOME%\bin\%proguardExec%" 79 80if exist "%proguard%" goto proguardOk 81REM set proguard location for the Android tree case 82 set "PROGUARD_HOME=%~dp0\..\..\..\..\external\proguard" 83 set "proguard=%PROGUARD_HOME%\bin\%proguardExec%" 84 85:proguardOk 86REM Capture all arguments. 87REM Note that when reading the input arguments with %1, the cmd.exe 88REM automagically converts --name=value arguments into 2 arguments "--name" 89REM followed by "value". Dx has been changed to know how to deal with that. 90set params= 91 92set output= 93set disableKeepAnnotated= 94 95:firstArg 96if [%1]==[] goto endArgs 97 98 if %1 NEQ --output goto notOut 99 set "output=%2" 100 shift 101 shift 102 goto firstArg 103 104:notOut 105 106 if %1 NEQ --disable-annotation-resolution-workaround goto notDisable 107 set "disableKeepAnnotated=%1" 108 shift 109 goto firstArg 110 111:notDisable 112 113 if %1 NEQ --aapt-rules goto notAapt 114 set "extrarules=%2" 115 shift 116 shift 117 goto firstArg 118 119:notAapt 120 if defined params goto usage 121 set params=%1 122 shift 123 goto firstArg 124 125:endArgs 126if defined params ( goto makeTmpJar ) else ( goto usage ) 127 128:makeTmpJar 129set "tmpJar=%TMP%\mainDexClasses-%RANDOM%.tmp.jar" 130if exist "%tmpJar%" goto makeTmpJar 131echo "" > "%tmpJar%" 132set "exitStatus=0" 133 134 135call "%proguard%" -injars %params% -dontwarn -forceprocessing -outjars "%tmpJar%" -libraryjars "%shrinkedAndroidJar%" -dontoptimize -dontobfuscate -dontpreverify -include "%baserules%" -include "%extrarules%" 1>nul 136 137if DEFINED output goto redirect 138call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder %disableKeepAnnotated% "%tmpJar%" "%params%" 139goto afterClassReferenceListBuilder 140:redirect 141call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder %disableKeepAnnotated% "%tmpJar%" "%params%" 1>"%output%" 142:afterClassReferenceListBuilder 143 144del %tmpJar% 145exit /b 146 147:usage 148echo "Usage : %0 [--output <output file>] <application path>" 149exit /b 1 150