Skip to content

Instantly share code, notes, and snippets.

@lacostej
Created March 29, 2012 08:51
Show Gist options
  • Save lacostej/2235151 to your computer and use it in GitHub Desktop.
Save lacostej/2235151 to your computer and use it in GitHub Desktop.
A script to post process the AndroidManifest.xml using apktool
# taken from http://forum.unity3d.com/threads/84953-Android-Permissions-and-the-Manifest.xml
#
if [ $# -ne 3 ]; then
echo "ERROR Missing argument"
echo "Usage: $0 file.apk newmanifest.xml target.apk"
exit -1
fi
APK=$1
MANIFEST=$2
TARGET_APK=$3
file=`basename $APK`
APKTOOL_HOME=/usr/local/bin/
REPACK_DIR=target/repack_apk
if [ ! -x $APKTOOL_HOME/apktool ]; then
echo "ERROR Missing or non executable apktool under $APKTOOL_HOME"
exit -1
fi
if [ ! -x $APKTOOL_HOME/aapt ]; then
echo "ERROR Missing or non executable aapt under $APKTOOL_HOME"
exit -1
fi
if [ ! -f $APK ]; then
echo "ERROR Invalid argument: missing apk file '$APK'"
exit -1
fi
if [ ! -f $MANIFEST ]; then
echo "ERROR Invalid argument: missing manifest file '$MANIFEST'"
exit -1
fi
if [ -d $REPACK_DIR ]; then
rm -rf $REPACK_DIR
fi
echo $PATH
$APKTOOL_HOME/apktool d $APK $REPACK_DIR
cp $MANIFEST $REPACK_DIR/AndroidManifest.xml
$APKTOOL_HOME/apktool b $REPACK_DIR
jarsigner -keystore ~/.android/debug.keystore -storepass android -keypass android $REPACK_DIR/dist/$file androiddebugkey
#jarsigner -verbose -keystore apktool/my-release-key.keystore $REPACK_DIR/dist/$file alias_name
if [ "$APK" == "$TARGET_APK" ]; then
mv "$APK" "$APK.old"
fi
zipalign -v 4 $REPACK_DIR/dist/$file $TARGET_APK
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment