Created
September 12, 2015 09:10
-
-
Save kvendrik/91ed9e8eaf10ecd0a2f7 to your computer and use it in GitHub Desktop.
Build 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
| if [ -z "$1" -o -z "$2" ] ; then | |
| printf 'Please supply a APK name and semver string\nusage: _build-android-apk <APK_NAME> <SEMVER_STRING>' | |
| exit 1 | |
| fi | |
| APK_NAME=$1 | |
| SEMVER_STRING=$2 | |
| function check_certificate(){ | |
| # create key if not present | |
| if [ ! -f ../../$APK_NAME-release-key.keystore ] ; then | |
| printf 'No certificate found!' | |
| exit 1 | |
| #keytool -genkey -v -keystore $APK_NAME-release-key.keystore -alias $APK_NAME -keyalg RSA -keysize 2048 -validity 10000 | |
| fi | |
| } | |
| function signapk(){ | |
| check_certificate | |
| # sign build | |
| printf '\n> sign apk\n' | |
| jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore $APK_NAME-release-key.keystore $1 $APK_NAME | |
| # zipalign build | |
| printf '\n> zipalign\n' | |
| zipalign -v 4 $1 build/outputs/apk/$APK_NAME-$SEMVER_STRING.apk | |
| } | |
| # only sign an already existant APK | |
| if [ "$3" = "--apk" ] ; then | |
| printf '\n> move to platforms/android' | |
| cd platforms/android | |
| signapk $4 | |
| printf "\nAPK should be in build/outputs/apk/$APK_NAME-$SEMVER_STRING.apk" | |
| exit 0 | |
| fi | |
| if [ -d platforms/android ] ; then | |
| printf '> making sure we have the right permissions' | |
| sudo chown -R $USER platforms/android | |
| sudo chown -R $USER plugins | |
| printf '\n> move to platforms/android' | |
| cd platforms/android | |
| printf '\n> build android release\n' | |
| ionic build android --release | |
| check_certificate | |
| signapk build/outputs/apk/android-armv7-release-unsigned.apk | |
| printf "\nAPK should be in build/outputs/apk/$APK_NAME-$SEMVER_STRING.apk" | |
| else | |
| echo 'platforms/android is not a directory' | |
| fi | |
| exit 0 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment