Publishing Ionic Apps on Android

Posted in Engineering

I had this assignment to publish Ionic app on Android. I did it before, but I always forgot how to do it properly. I am writing this as a personal note and reminder in case I forgot on how to do it, and I definitely don’t want to waste my time searching on Google every time I need to publish an Ionic app. (Though, you can check the official documentation from Ionic regarding deployments).

I am writing this as I am trying to publish my app.

Build Production Release

Simply run $ ionic cordova build android --prod --release on your project directory.

You will get an APK inside platforms/android/build/outputs/apk as a result of the command above. Note the path is relative to your project directory.

Create Keystore Using Android Studio

I don’t exactly know why, but when I am generating keystore using keytool, Google Play just won’t accept (probably just on my machine). Please feel free to tell me about this. See the official documentation on creating keystore from Android Studio.

Once you generated your keystore, you will be using that keystore to sign your APK. Replace bold code with your own.

$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore **your-keystore** **platforms/android/build/outputs/apk/android-release-unsigned.apk** **keystore-alias**

In case you are interested in generating keystore using keytool, use the command below.

keytool -genkey -v -keystore **my-release-key.jks** -keyalg RSA -keysize 2048 -validity 10000 -alias **my-alias**

Zip Align Your APK

To optimize your APK, we use zipalign tools provided by the Android SDK. You should be able to find it inside your Android SDK installation folder, then build-tools/{VERSION}/zipalign.

Because I set my $ANDROID_HOME path, I can simply run it as below:

$ $ANDROID_HOME/build-tools/26.0.2/zipalign.exe -v 4 **platforms/android/build/outputs/apk/android-release-unsigned.apk** **aligned.apk**

I am using Git Bash on Windows, the way you call environment variable might be different depending on your platform. Replace the bold code with your own values.

Important

Make sure that you updated your version and version code on release. Google Play Store will rejects APK with the same version code that already exists.