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"
26
27REM Locate dx.jar in the directory where dx.bat was found.
28set jarfile=dx.jar
29set "frameworkdir=%~dp0"
30rem frameworkdir must not end with a dir sep.
31set "frameworkdir=%frameworkdir:~0,-1%"
32if exist "%frameworkdir%\%jarfile%" goto JarFileOk
33    set "frameworkdir=%~dp0lib"
34
35if exist "%frameworkdir%\%jarfile%" goto JarFileOk
36    set "frameworkdir=%~dp0..\framework"
37:JarFileOk
38
39set "jarpath=%frameworkdir%\%jarfile%"
40
41set "shrinkedAndroidJar=%SHRINKED_ANDROID_JAR%
42if exist "%shrinkedAndroidJar%" goto shrinkedAndroidOk
43    set "shrinkedAndroidJar=shrinkedAndroid.jar"
44
45if exist "%shrinkedAndroidJar%" goto shrinkedAndroidOk
46    set "shrinkedAndroidJar=%frameworkdir%\%shrinkedAndroidJar%"
47
48:shrinkedAndroidOk
49set "proguardExec=proguard.bat"
50set "proguard=%PROGUARD_HOME%\bin\%proguardExec%"
51
52if exist "%proguard%" goto proguardOk
53REM set proguard location for the SDK case
54    set "PROGUARD_HOME=%~dp0\..\..\tools\proguard"
55    set "proguard=%PROGUARD_HOME%\bin\%proguardExec%"
56
57if exist "%proguard%" goto proguardOk
58REM set proguard location for the Android tree case
59    set "PROGUARD_HOME=%~dp0\..\..\..\..\external\proguard"
60    set "proguard=%PROGUARD_HOME%\bin\%proguardExec%"
61
62:proguardOk
63REM Capture all arguments.
64REM Note that when reading the input arguments with %1, the cmd.exe
65REM automagically converts --name=value arguments into 2 arguments "--name"
66REM followed by "value". Dx has been changed to know how to deal with that.
67set params=
68
69set output=
70
71:firstArg
72if [%1]==[] goto endArgs
73
74    if %1 NEQ --output goto notOut
75        set "output=%2"
76        shift
77        shift
78        goto firstArg
79
80:notOut
81    if defined params goto usage
82    set params=%1
83    shift
84    goto firstArg
85
86:endArgs
87if defined params ( goto makeTmpJar ) else ( goto usage )
88
89:makeTmpJar
90set "tmpJar=%TMP%\mainDexClasses-%RANDOM%.tmp.jar"
91if exist "%tmpJar%" goto makeTmpJar
92echo "" > "%tmpJar%"
93set "exitStatus=0"
94
95
96call "%proguard%" -injars %params% -dontwarn -forceprocessing  -outjars "%tmpJar%" -libraryjars "%shrinkedAndroidJar%" -dontoptimize -dontobfuscate -dontpreverify -include "%baserules%" 1>nul
97
98if DEFINED output goto redirect
99call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder "%tmpJar%" "%params%"
100goto afterClassReferenceListBuilder
101:redirect
102call "%java_exe%" -Djava.ext.dirs="%frameworkdir%" com.android.multidex.MainDexListBuilder "%tmpJar%" "%params%" 1>"%output%"
103:afterClassReferenceListBuilder
104
105del %tmpJar%
106exit /b
107
108:usage
109echo "Usage : %0 [--output <output file>] <application path>"
110exit /b 1
111