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:
1 |
keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000 |
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:
1 2 3 4 5 6 7 8 9 |
# Your Application Makefile .PHONY: package-android package-android: cordova build --release android \ && cd platforms/android/build/outputs/apk \ && jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../../../../../../KeyStores/yourapplication.keystore android-release-unsigned.apk yourapplication \ && rm YourApplication.apk \ && ./zipalign -v 4 android-release-unsigned.apk YourApplication.apk |
Basically what this does is..
- Created a unsigned apk called: android-release-unsigned.apk
- cd into platforms/android/build/outputs/apk (where this apk is)
- use jarsigner to sign that apk with your keyfile you generated above
- 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.
- Also you may need to change this dir ../../../../../../KeyStores/yourapplication.keystore to where your keyfile is located.
- Then it will remove YourApplication.apk (change this name if you want)
- 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.
No Comments