Skip to content

Instantly share code, notes, and snippets.

@codeniko
Last active February 10, 2019 05:20
Show Gist options
  • Save codeniko/cdc8ff7dd4efc8fbceae55c0e6b165b0 to your computer and use it in GitHub Desktop.
Save codeniko/cdc8ff7dd4efc8fbceae55c0e6b165b0 to your computer and use it in GitHub Desktop.
sign apk
#!/bin/bash
# Key Vars
keyfile='my-release-key.jks'
# APK Vars
filename="${1%.*}"
ext='.apk'
aligned="$filename-aligned$ext"
signed="$filename-signed$ext"
function generate_key {
echo 'Need to generate release key, fill out the information below'
keytool -genkey -v -keystore "$keyfile" -keyalg RSA -keysize 2048 -validity 10000 -alias my-alias
}
function sign_apk {
echo "Signing $1"
zipalign -v -p 4 "$1" "$aligned"
apksigner sign --ks "$keyfile" --out "$signed" "$aligned"
}
if [ -f "$keyfile" ]; then
sign_apk "$1"
else
generate_key
if [ "$?" -eq 0 ]; then
sign_apk "$1"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment