Last active
April 23, 2020 12:14
-
-
Save mirkonasato/19076247cf966b33fd03 to your computer and use it in GitHub Desktop.
Sign and align an Android APK
This file contains 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" |
I feel that some people will put this script on the root of their ionic project and run into troubles. So maybe it's better to update the example to use ./
./signalign platforms/android/build/outputs/apk/android-release-unsigned.apk
and remember people to grant execution permissions to the file
sudo chmod +x signalign
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,

I'm trying to use this script but for some reason it won't recognize jarsigner.
I tried to use the full path to jarsigner but then it won't recognize -sigalg
Where should my jarsigner be?
thanks.