Checking Android app publish status in Google play

After publishing an Android app in the Google Developer Console, I wonder how long it will take Google to list it the Play store.

At first I manually checked Google Play every now and then.  Eventually I wrote a BASH script to do just that:

data=`curl -s https://play.google.com/store/apps/details?id=$appid`
echo $data | grep -q "What's New"
if [ $? -eq 0 ]; then
    espeak "application is published"

Here is what it does:

1. Ask curl to retrieve the search result from Google Play, using the reverse domain app id as the search key.

2. Ask grep to find a text string "What's New" in the search result.  If found, it is safe to assume the app is now listed.

3. Ask the computer to let me know verbally.

The -s option of curl and the -q option of grep just tell curl and grep not to write any output to the screen.

I then schedule the BASH script in crontab to run every five minutes. Now I will know the moment the app is listed in Google Play.


How I turn my website into an Android App - Part 3

In part 3 of this blog post, we are going to prepare the release version of the apk and publish it to Google Play store.

In order to publish an app to Google Play, the apk has to be signed and zip aligned. We are going to do both of them.

Step 1 
Use the keytool utility bundled with the Oracle JDK to generate a private key for signing the apk:

Assuming we are still in the amg directory, 

$ keytool -genkey -v -keystore ./amg.keystore -alias amgkey -keyalg RSA -keysize 2048 -validity 10000


"./amg.keystore" = the name and location of the key store
"amgkey" = the name of the key to generate

The encryption algorithm is RSA with a key size of 2048 bits, and the generated key is valid for 10,000 days (27 years).

It will ask you for a passphrase to protect the key store, and a bunch of other questions such as your first and last name, company name, etc.

It will also ask you for a passphrase to protect the key, with the option of using the same passphrase you choose for the key store.

Step 2 
Use the jarsigner utility bundled with the Oracle JDK to sign the apk with the generated key:

$ jarsigner -verbose -sigalg MD5withRSA -digestalg SHA1 -keystore ./amg.keystore platforms/android/bin/AMG-release-unsigned.apk amgkey


signature algorithm = MD5 with RSA
digest algorithm = SHA1

It will ask you for the passphrase to the key store.  The apk will be signed in place.

Step 3 
Use the zipalign utility bundled with the Android SDK to align the apk, which is basically a zip file:

zipalign -v 4 platforms/android/bin/AMG-release-unsigned.apk amg.apk


-v = verbose output
 4 = alignment in bytes

The signed and zip aligned amg.apk is now ready to upload to Google Play.

That's it.  Hope you like this post.


How I turn my website into an Android App - Part 2

In part 2 of this blog post, we are going to convert my website into an Android app using Cordova command line interface (CLI).

Step 1 
Create a Cordova project to host the website.

$ cordova create amg com.amgcomputing.website AMG

amg = directory to host the project files
com.amgcomputing.website = reverse domain-style project identifier
AMG = display name of the app

Step 2
Since I am only interested in the Android platform in this post, I remove all icon and screen resources for other platforms.

$ cd amg

$ rm -rf www/res/icon/bada
$ rm -rf www/res/icon/bada-wac
$ rm -rf www/res/icon/blackberry
$ rm -rf www/res/icon/ios
$ rm -rf www/res/icon/tizen
$ rm -rf www/res/icon/webos
$ rm -rf www/res/icon/windows-phone

$ rm -rf www/res/screen/bada
$ rm -rf www/res/screen/bada-wac
$ rm -rf www/res/screen/blackberry
$ rm -rf www/res/screen/ios
$ rm -rf www/res/screen/tizen
$ rm -rf www/res/screen/webos
$ rm -rf www/res/screen/windows-phone

Step 3
Add android platform support to the project.

$ cordova platform add android

Step 4
To keep it simple, I am going to delete the higher resolution drawable resources that come with the platform:

$ rm -rf platforms/android/res/drawable-hdpi
$ rm -rf platforms/android/res/drawable-ldpi
$ rm -rf platforms/android/res/drawable-mdpi
$ rm -rf platforms/android/res/drawable-xhdpi

Then I replace the icon resource (96x96 pixels) that comes with the platform with my own version of it:


Step 5
Here is the directory structure of my Bootstrap v3 based website.  I built it using the starter-template.

|_ assets
|  |_ js
|_ dist
   |_ css
   |_ js

I put a copy of my website in the www folder of the cordova project, replacing the index.html there.

Step 6
I like to set my app at version 1.0, so I change the version name from the default of "0.0.1" to "1.0" in the www/config.xml file.  During the build process, Cordova will automatically update the Android Manifest (AndroidManifest.xml) located in the platforms/android direcotry to reflect this change.

$ sed -i'' 's/version="0.0.1"/version="1.0"/' www/config.xml

The -i'' option is for in place editing without making any backup.

Step 7
Build the project to generate a debug apk:

$ cordova build android

The generated debug apk is located at:

You can also test the app by running it in the Android Virtual Device (AVD) created in Part 1 of this post:

$ cordova emulate android

Step 8
Next is to create a release version of the apk:

$ cordova build --release android

The generated release apk is located at:

Step 9
Now we are ready to prepare the release apk for publishing to the Google Play store.

See you in Part 3 of this post.

How I turn my website into an Android app - Part 1

This is an account on how I turned a website into an Android app. The website is built with Bootstrap v3.  I am going to use Apache Cordova v3.0.6 (aka PhoneGap) to convert it into an app.  Almost everything is done in the command line, and the operating system in use is Debian 6.x.  Let's see the result first.  

The website:

The Android app:

or you can see the app website here:


This post is divided into three parts:
1. Set up the Cordova environment.
2. Convert the website into an Android app.
3. Publish the Android app to Google Play.

Here is part 1 of the post.

Step 1 
Cordova is installed by Node.js. So we need to intall Node.js first.  We will install it locally in the user's home folder so that we do not root access.

$ wget http://nodejs.org/dist/v0.10.18/node-v0.10.18.tar.gz
$ tar -xzvf node-v0.10.18.tar.gz
$ cd node-v0.10.18
$ ./configure --prefix=$HOME
$ make
$ make install

It will take some time to "make" Node.js.  Please be patient.  Eventually, the Node.js package manager (npm) will be installed in the ~/bin folder.  

Step 2 
Install Apache Cordova using the Node.js package manager (npm).

$ npm install -g cordova

Step 3
Download the ADT (Android Developer Tools) bundle from the Android Developer website here.  We need the ADT to build the Android app.

As of this writing, I have downloaded the following zip file for my Debian 6 (32-bit). You will have to agree with Google terms and conditions before you can download the ADT.

   adt-bundle-linux-x86-20130729.zip (Linux 32-bit)

Unzip it and move its content to a convenient location:

$ unzip adt-bundle-linux-x86-20130729.zip
$ mkdir ~/android
$ mv adt-bundle-linux-x86-20130729/eclipse ~/android
$ mv adt-bundle-linux-x86-20130729/sdk ~/android

Step 4
Download Oracle JDK.  We need the JDK to compile the java source files.  OpenJDK may or may not work.  Your mileage may vary.

The Oracle JDK can be downloaded from the Oracle website here.  You must accept Oracle's license agreement in order to download the JDK.

As of this writing, I have downloaded the following file for my Debian 6 (32-bit):

   jdk-7u25-linux-i586.tar.gz (Linux x86)

Untar it and move it to a convenient location:

$ tar -xzvf jdk-7u25-linux-i586.tar.gz
$ mv jdk1.7.0_25 ~/android

Step 5
Add various paths in ~/.bashrc for convenience:

echo 'PATH="$HOME/bin:$PATH"' >> ~/.bashrc
echo 'PATH="$HOME/android/sdk/tools:$PATH"' >> ~/.bashrc
echo 'PATH="$HOME/android/sdk/platform-tools:$PATH"' >> ~/.bashrc
echo 'PATH="$HOME/android/jdk1.7.0_25/bin:$PATH"' >> ~/.bashrc
echo 'PATH="$HOME/android/eclipse:$PATH"' >> ~/.bashrc

Step 6
Install the Android API by starting the Android SDK Manager:

$ android

and follow the on screen instruction to install the Android API. In this writing, I installed Android 4.3 (API 18).

You may also like to create an Android Virtual Device (AVD) for testing purpose.  You can start the Android Virtual Device Manager from the Android SDK Manager by going to the "Tools" menu and select "Manage AVDs...".

We are now ready to move on to Part 2 of this post, i.e. to convert the website into an Android app using Cordova.

Please note that Cordova can build mobile apps in multiple platforms, including Android, iOS, etc.  In this post, we will focus in Android only.