apktool 2.6 KB

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