Skip to content

Instantly share code, notes, and snippets.

@amitpdev
Created August 9, 2017 17:15
Show Gist options
  • Save amitpdev/f03a0a591dbfbcc6ea429b54c4e01f95 to your computer and use it in GitHub Desktop.
Save amitpdev/f03a0a591dbfbcc6ea429b54c4e01f95 to your computer and use it in GitHub Desktop.
Generate a signed APK for Android with React Native
#!/bin/bash
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <certificate_key.jks>"
exit 1
fi
function loginfo {
GREEN="\033[92m"
CLEAR="\033[0m"
echo -e "${GREEN}[INFO] ${1}${CLEAR}"
}
loginfo "Bundling React Native resources"
react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/
loginfo "Deleting old apk files"
cd android
\rm *.apk 2>/dev/null
\rm app/build/outputs/apk/*.apk 2>/dev/null
loginfo "Compiling release build"
./gradlew assembleRelease
cd ..
loginfo "Aligning archive"
zipalign -v -p 4 android/app/build/outputs/apk/app-release-unsigned.apk android/app-unsigned-aligned.apk
loginfo "Signing archive"
apksigner sign --ks $1 --out nester-release.apk --ks-pass stdin --key-pass stdin android/app-unsigned-aligned.apk
loginfo "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment