apktool
1 #!/bin/bash 2 # 3 # Copyright (C) 2007 The Android Open Source Project 4 # 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 8 # 9 # https://www.apache.org/licenses/LICENSE-2.0 10 # 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. 16 17 # This script is a wrapper for apktool.jar, so you can simply call "apktool", 18 # instead of java -jar apktool.jar. It is heavily based on the "dx" script 19 # from the Android SDK 20 21 # Set up prog to be the path of this script, including following symlinks, 22 # and set up progdir to be the fully-qualified pathname of its directory. 23 prog="$0" 24 while [ -h "${prog}" ]; do 25 newProg=`/bin/ls -ld "${prog}"` 26 27 newProg=`expr "${newProg}" : ".* -> \(.*\)$"` 28 if expr "x${newProg}" : 'x/' >/dev/null; then 29 prog="${newProg}" 30 else 31 progdir=`dirname "${prog}"` 32 prog="${progdir}/${newProg}" 33 fi 34 done 35 oldwd=`pwd` 36 progdir=`dirname "${prog}"` 37 cd "${progdir}" 38 progdir=`pwd` 39 prog="${progdir}"/`basename "${prog}"` 40 cd "${oldwd}" 41 42 jarfile=apktool.jar 43 libdir="$progdir" 44 if [ ! -r "$libdir/$jarfile" ] 45 then 46 # Find the highest version of apktool_*.jar in the directory. 47 highest_jarfile=$(ls "$libdir"/apktool_*.jar 2>/dev/null | sort -V | tail -n 1) 48 if [ -n "$highest_jarfile" ]; then 49 jarfile=$(basename "$highest_jarfile") 50 else 51 echo `basename "$prog"`": can't find $jarfile" 52 exit 1 53 fi 54 fi 55 56 javaOpts="" 57 58 # If you want DX to have more memory when executing, uncomment the following 59 # line and adjust the value accordingly. Use "java -X" for a list of options 60 # you can pass here. 61 # 62 javaOpts="-Xmx1024M -Dfile.encoding=utf-8 -Djdk.util.zip.disableZip64ExtraFieldValidation=true -Djdk.nio.zipfs.allowDotZipEntry=true" 63 64 # Alternatively, this will extract any parameter "-Jxxx" from the command line 65 # and pass them to Java (instead of to dx). This makes it possible for you to 66 # add a command-line parameter such as "-JXmx256M" in your ant scripts, for 67 # example. 68 while expr "x$1" : 'x-J' >/dev/null; do 69 opt=`expr "$1" : '-J\(.*\)'` 70 javaOpts="${javaOpts} -${opt}" 71 shift 72 done 73 74 if [ "$OSTYPE" = "cygwin" ] ; then 75 jarpath=`cygpath -w "$libdir/$jarfile"` 76 else 77 jarpath="$libdir/$jarfile" 78 fi 79 80 # add current location to path for aapt 81 PATH=$PATH:`pwd`; 82 export PATH; 83 exec java $javaOpts -Djava.awt.headless=true -jar "$jarpath" "$@"