File: mainDexClasses

package info (click to toggle)
android-platform-dalvik 10.0.0%2Br36-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 26,132 kB
  • sloc: java: 270,758; cpp: 8,766; sh: 2,004; javascript: 976; ansic: 534; awk: 368; makefile: 26
file content (180 lines) | stat: -rwxr-xr-x 4,713 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/bin/bash
#
# Copyright (C) 2013 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function makeTempJar ()
{
  local tempDir=/tmp
  if [ ! -e "${tempDir}" ]; then
    tempDir=.
  fi
  local tempfile="${tempDir}/mainDexClasses-$$.tmp.jar"
  if [ -e "${tempfile}" ]; then
    echo "Failed to create temporary file" >2
    exit 6
  fi
  echo "${tempfile}"
}

function cleanTmp ()
{
  if [ -e "${tmpOut}" ] ; then
    rm "${tmpOut}"
  fi
}


# Set up prog to be the path of this script, including following symlinks,
# and set up progdir to be the fully-qualified pathname of its directory.
prog="$0"

while [ -h "${prog}" ]; do
    newProg=`/bin/ls -ld "${prog}"`
    newProg=`expr "${newProg}" : ".* -> \(.*\)$"`
    if expr "x${newProg}" : 'x/' >/dev/null; then
        prog="${newProg}"
    else
        progdir=`dirname "${prog}"`
        prog="${progdir}/${newProg}"
    fi
done
oldwd=`pwd`
progdir=`dirname "${prog}"`
cd "${progdir}"
progdir=`pwd`
prog="${progdir}"/`basename "${prog}"`
cd "${oldwd}"

baserules="${progdir}"/mainDexClasses.rules
if [ ! -r "${baserules}" ]; then
    echo `basename "$prog"`": can't find mainDexClasses.rules" 1>&2
    exit 1
fi

extrarules="${progdir}"/mainDexClassesNoAapt.rules
if [ ! -r ${extrarules} ]; then
    echo `basename "$prog"`": can't find mainDexClassesNoAapt.rules" 1>&2
    exit 1
fi

jarfile=dx.jar
libdir="$progdir"

if [ ! -r "$libdir/$jarfile" ]; then
    # set dx.jar location for the SDK case
    libdir="$libdir/lib"
fi


if [ ! -r "$libdir/$jarfile" ]; then
    # set dx.jar location for the Android tree case
    libdir=`dirname "$progdir"`/framework
fi

if [ ! -r "$libdir/$jarfile" ]; then
    echo `basename "$prog"`": can't find $jarfile" 1>&2
    exit 1
fi

proguardExec="proguard.sh"
proguard=/usr/bin/proguard

if [ ! -r "${proguard}" ]; then
  # set proguard location for the SDK case
  proguardBaseDir=`dirname "$progdir"`
  # "${progdir}"/../..
  proguardBaseDir=`dirname "$proguardBaseDir"`
  proguard="${proguardBaseDir}"/tools/proguard/bin/${proguardExec}
fi

if [ ! -r "${proguard}" ]; then
  # set proguard location for the Android tree case
  proguardBaseDir=`dirname "$proguardBaseDir"`
  # "${progdir}"/../../../..
  proguardBaseDir=`dirname "$proguardBaseDir"`
  proguard="${proguardBaseDir}"/external/proguard/bin/${proguardExec}
fi

if [ ! -r "${proguard}" ]; then
  proguard="${ANDROID_BUILD_TOP}"/external/proguard/bin/${proguardExec}
fi

if [ ! -r "${proguard}" ]; then
    proguard="`which proguard`"
fi

if [ -z "${proguard}" -o ! -r "${proguard}" ]; then
    proguard="`which ${proguardExec}`"
fi

if [ -z "${proguard}" -o ! -r "${proguard}" ]; then
    echo `basename "$prog"`": can't find ${proguardExec}" 1>&2
    exit 1
fi

shrinkedAndroidJar="${SHRINKED_ANDROID_JAR}"
if [ -z "${shrinkedAndroidJar}" ]; then
  shrinkedAndroidJar=shrinkedAndroid.jar
fi

if [ ! -r "${shrinkedAndroidJar}" ]; then
  shrinkedAndroidJar=${libdir}/${shrinkedAndroidJar}
fi

if [ ! -r "${shrinkedAndroidJar}" ]; then
    echo `basename "$prog"`": can't find shrinkedAndroid.jar" 1>&2
    exit 1
fi

if [ "$OSTYPE" = "cygwin" ]; then
    # For Cygwin, convert the jarfile path into native Windows style.
    jarpath=`cygpath -w "$libdir/$jarfile"`
  proguard=`cygpath -w "${proguard}"`
  shrinkedAndroidJar=`cygpath -w "${shrinkedAndroidJar}"`
else
    jarpath="$libdir/$jarfile"
fi

disableKeepAnnotated=

while true; do
if expr "x$1" : 'x--output' >/dev/null; then
    exec 1>$2
    shift 2
elif expr "x$1" : 'x--disable-annotation-resolution-workaround' >/dev/null; then
    disableKeepAnnotated=$1
    shift 1
elif expr "x$1" : "x--aapt-rules" >/dev/null; then
    extrarules=$2
    shift 2
else
    break
fi
done

if [ $# -ne 1 ]; then
  echo "Usage : $0 [--output <output file>] <application path>" 1>&2
  exit 2
fi

tmpOut=`makeTempJar`

trap cleanTmp 0

"${proguard}" -injars ${@} -dontwarn -forceprocessing  -outjars "${tmpOut}" \
  -libraryjars "${shrinkedAndroidJar}" -dontoptimize -dontobfuscate -dontpreverify \
  -include "${baserules}" -include "${extrarules}" 1>/dev/null || exit 10

java -cp "$jarpath" com.android.multidex.MainDexListBuilder ${disableKeepAnnotated} "${tmpOut}" ${@} ||  exit 11