I’ve published a couple of apps to the Google Play store now, and when I came to do the same for a new app I’ve been working on, I had completely forgotten the steps involved and had to read all of the documentation again. It’s not straightforward, and involves a lot of commands in the terminal.
This as it is, I’ve resolved to document the process here so that, at the very least, I’ll be able to remember for next time. Hopefully this will help you too. Thanks go our to this article here which really helped me get to grips with the concepts (and which I’m mainly just elaborating on here).
The app I set out to make was to keep score in the word-based board game Scrabble. I built it over the course of a couple of weeks using Yeoman to create the project structure, which allows easy integration of Bower components and Grunt tasks. When generating the project with Yeoman, I opted to include Bootstrap to give me a head start on the styles, and SASS to organise and compile my CSS. At the end of development, you can run
to minify and concatenate all files and prepare them for distribution.
Whatever your method for creating a web application, you go ahead and do it. It could just be static HTML if you feel that it makes a useful app for someone. Either way, now you have an app. Next stage is to get Phonegap involved to convert it to an Android app.
First, make sure you have Phonegap installed:
sudo npm install -g phonegap
This does have a dependency on NodeJS, so make sure to go get that. Then you’ll want to create the Phonegap project. In a suitable directory, run:
phonegap create my-app cd my-app phonegap run android
This creates the directory ‘my-app’ (in this case, obviously feel free to call it something that resembles your app name) and puts a whole whack of files in it.
You can now copy all of your web app files into the my-app/www directory, replacing those that had been created for their default ‘HelloWorld’ application.
Prepping your app
In order for your app to know what it is in the world, you’ll have to update a few definitions in some xml files. First up, go through the www/config.xml file, and update all the info so it looks like your app and your details. Also in here in the ‘widget’ tag is the version attribute. This is the version number that’s displayed to users in the Google Play Store.
The other file you’ll need to update is platforms/android/AndroidManifest.xml – this contains references to your package name (which you’ll want to change to com.yourcompany.yourappname), you’ll want to add the attribute:
to the ‘application’ tag, and each time you want to publish a new version you’ll have to increment the ‘android:versionCode’ attribute on the ‘manifest’ tag. You can only go up in whole integers, and this the the version that the Play Store itself uses to recognise a newer version of your app.
Generating a keystore file
Run the following command
keytool -genkey -v -keystore my-app-key.keystore -alias app_key -keyalg RSA -keysize 2048 -validity 10000
Follow the prompts and it will create a keystore file in the folder you run it from (with the name ‘my-app-key.keystore’ or whatever you put in that bit of the command). It’s recommended not to keep this in the same file as your app, and certainly don’t put it in a public Github repository. You should create a new one for every app you make.
Next, create a new file called ‘ant.properties’ inside platforms/android in this, save the following information
the relative path should point to where you saved your keystore file, and the alias is as specified in the keystore generation command.
Signing in release mode
Run this in your phonegap project:
phonegap build android
You’ll then want to run the following, which will create release versions of the app:
cd platforms/android ant release
Follow the prompts and enter your keystore password where required.
There will now be some new files inside the bin directory, have a look, as you’ll have to target one of them at the next stage.
To sign the files, you’ll need to head to the bin directory and run the following:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ../../../../my-app-key.keystore MyApp-release-unsigned.apk app_key
Where ‘../../../../my-app-key.keystore’ points to your keystore file, ‘MyApp-release-unsigned.apk’ is the ‘…-release-unsigned.apk’ file just created and ‘app_key’ is the alias name for your keystore.
Enter your keystore password again when prompted.
Verify the signing like so:
jarsigner -verify -verbose -certs MyApp-release-unsigned.apk
Finally, you need to zipalign your newly signed file. This does some compression and optimisation and saves the file to a new name as specified
zipalign -v 4MyApp-release-unsigned.apk MyApp.apk
I had an issue where zipalign gave a ‘Command not found’ error. This was resolved by searching for where zipalign lived on my system and including the file reference in the command e.g.
/Users/riley/Development/adt-bundle/sdk/build-tools/21.1.2/zipalign -v 4 MyApp-release-unsigned.apk MyApp.apk
This generates the final MyApp.apk file you can upload directly to the Google Play Store.
Hope this of help to someone other than me. Happy apping!