-
-
Save dancr13/535e4f2291686eee3bea to your computer and use it in GitHub Desktop.
Sign and align an Android APK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Automates signing and aligning Android APKs as per | |
# http://developer.android.com/tools/publishing/app-signing.html#signing-manually | |
# | |
# USAGE: signalign platforms/android/build/outputs/apk/android-release-unsigned.apk | |
# | |
set -e | |
# configure the next two properties for your own certificate | |
KEYSTORE_PATH="$HOME/path/to/your/android-release.keystore" | |
KEY_ALIAS="your-key-alias" | |
UNSIGNED_APK="$1" | |
APK_NAME="$(basename "$UNSIGNED_APK" -unsigned.apk)" | |
TARGET_DIR="$(dirname $UNSIGNED_APK)" | |
SIGNED_APK="$TARGET_DIR/$APK_NAME-signed.apk" | |
SIGNED_ALIGNED_APK="$TARGET_DIR/$APK_NAME-signed-aligned.apk" | |
BUILD_TOOLS_VERSION="$(ls -1 "$ANDROID_HOME/build-tools" | tail -n 1)" | |
ZIPALIGN="$ANDROID_HOME/build-tools/$BUILD_TOOLS_VERSION/zipalign" | |
echo "Signing: $SIGNED_APK" | |
cp "$UNSIGNED_APK" "$SIGNED_APK" | |
jarsigner -sigalg MD5withRSA -digestalg SHA1 \ | |
-keystore "$KEYSTORE_PATH" "$SIGNED_APK" "$KEY_ALIAS" | |
echo "Aligning: $SIGNED_ALIGNED_APK" | |
rm -f "$SIGNED_ALIGNED_APK" | |
$ZIPALIGN -v 4 "$SIGNED_APK" "$SIGNED_ALIGNED_APK" | |
echo "All done. Your final APK is $SIGNED_ALIGNED_APK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment