Coding

How to create PhoneGap android apk for release in an automated way

September 19, 2017

Recently I decided to make one of my ReactJs websites http://www.cantonesenumbers.co.uk into an android application. I could have gone down the route of building it from scratch natively, or even built it using e.g. ReactNative.. I decided the smartest and quickest solution would be to convert it to an app using cordova phonegap.

Once I had turned it into an app (in another blog post I will go into this), I needed to release my app to the android app store. The first time I followed this tutorial:  https://codesundar.com/lesson/publish-cordova-apps-to-playstore/ and it worked great! However… remembering all of those steps every time I wanted to make a new release apk seemed like a chore, especially in the more automated coding world we live in.

I have created a single make command (make package-android) to simple create a release apk with just that command. Here is what you need todo!

1. Download and install “make” if you don’t already have it

For windows: http://gnuwin32.sourceforge.net/packages/make.htm

For osx: you should already have the make comand, you may need to install xcode though to get it.

2. Create a key store for signing your android app

Run this command:

Changing:

my-release-key.keystore to yourappname.keystore and alias_name to yourappname

It will ask you for a password, remember this as you will need it everytime you want to publish an new app. (trust me… i’ve learnt this the hard way!)

Then store this somewhere safe e.g. I have /Code/Apps/PhoneGap/KeyStores/ dir

3. Create a Makefile in the root of your phonegap project

in terminal run: touch Makefile

4. Open that makefile and add this to it

Open however you want e.g. atom Makefile, code Makefile, vim Makefile etc etc…

Input in it:

Basically what this does is..

  1. Created a unsigned apk called: android-release-unsigned.apk
  2. cd into platforms/android/build/outputs/apk (where this apk is)
  3. use jarsigner to sign that apk with your keyfile you generated above
  4. In this bit “yourapplication.keystore android-release-unsigned.apk yourapplication” you will need to change yourapplication.keystore with the name of your file and yourapplication at the end with the name of the alias you gave the keyfile.
  5. Also you may need to change this dir ../../../../../../KeyStores/yourapplication.keystore to where your keyfile is located.
  6. Then it will remove YourApplication.apk (change this name if you want)
  7. Then the finals stage it will zipalign the apk and make a YourApplication.apk out of the unsigned.apk

One last thing I needed to put in “platforms/android/build/outputs/apk” dir the zipalign program (you will find this in the android sdk folder).

Then whenever you want to make a new release.. you just need to run “make package-android” instead of doing all of these steps manually.

You Might Also Like

No Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.