6 super easy commands to publish Android PhoneGap application to Google Play Store

6 Commands to Publish PhoneGap Apps to Playstore
07 March, 2017
Fady Soliman
138 Views
 1 user marked as helpfull

Introduction to converting a PhoneGap app into an Android APK

If you have reached this post, either by a Google search or a referral link, then you are probably a hybrid mobile applications developer who's looking to publish his PhoneGap app to the play store. You might have also experienced that PhoneGap is a super easy framework that makes mobile apps development a very easy task despite all the drawbacks having a mobile application running on a web view.

The good news is: Packaging the PhoneGap application to Google play store is even much easier.

In this post, I will assume you have finished your mobile application's design and development and ready to publish it to the store. I am going to walk you through the publishing process step by step starting with your PhoneGap application. The first part of the process is to convert your PhoneGap application files (HTML, JS, CSS and media files like images) to a packaged Android APK file.


Prerequisites

You are going to use the PhoneGap CLI to build and package the target signed apk (discussed later). If you haven't installed the PhoneGap CLI yet, make sure you install the following:

  1. NodeJS from NodeJS site
  2. PhoneGap CLI (Command Line Interface) by running the following command:
npm install -g phonegap@latest


For more information about the PhoneGap CLI commands, go to http://docs.phonegap.com/getting-started/1-install-phonegap/cli/.


Step 1: Packaging PhoneGap application files into an APK

Assuming you are working on a windows environment, open a command prompt and go to the PhoneGap application's directory, for example:


cd C:\\PhoneGap\App


where C:\\PhoneGap\App is your PhoneGap application's main directory, then run the following command that will build the PhoneGap application and produce the Android debug APK version:


phonegap build android 


The build command would produce the debug version of the apks as well as creating some other necessary gradle build files if they are not yet created. To make sure that this command worked as expected you would see the command result on the command prompt as shown in the following screenshot.

phonegap build android command result

Also if you browsed on your file explorer to the folder path: App\platforms\android\build\outputs\apk You would find a couple of files have been created. android-debug.apk and android-debug-unaligned.apk.


Step 2: Gradle building to produce the unsigned APK

The second step is to create the unsigned APK file that would be used in the subsequent signing steps. On your command prompt, browse to the platforms\android folder as follows:


cd platforms\android 


Then type in the following command to produce the unsigned APK:


gradlew build 


The above build command would produce a third APK file called android-release-unsigned.apk.

Note: Ignore any build failure messages as long as you find that third new APK unsigned file.


Step 3: Generating a key store file

In order to be able to upload the APK produced in step 2 to the play store it must be signed first. To get the APK signed you must use a file called the key store file. If you have created one then skip to Step 4, if not then run the following command to create one:


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


The above command will result in asking you some questions on the command prompt. Keep answering those questions until you reach the password question, keep that password along with the alias you provided in the previous command saved somewhere to be able to use it in the future because signing the APK process will ask you for that password. Once you finished you should see your key store file generated. It's a file with a .keystore extension.


Step 4: Signing the APK

In this step you would sign the unsigned APK generated in Step 2 with the key store file generated in Step 3. First, move the key store file to the path where the android-release-unsigned.apk is placed in your android PhoneGap application. Usually the apk is saved in C:\\<your_phonegap_app_path\platforms\android\build\outputs\apk. We moved the key store file to where the unsigned APK is to make it easier dealing with file paths and command errors due to invalid ones. Now sign the apk by running the following command


jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore android-release-unsigned.apk my-alias


You'd be asked for the password you saved in Step 3. Then you should find a success message as "jar signed" and you can ignore the warning message if any.


Step 5: Verify the signed APK

The next step is to verify the signed APK by running the following command


jarsigner -verbose -verify -certs android-release-unsigned.apk


After running this command you should get a success message as "jar verified" and you can also ignore any warning messages.


Step 6: Generating the aligned final signed APK for the play store

The final step is to generate the APK that you will use to upload to the play store. That one would be generated by running the following command:


zipalign -v 4 android-release-unsigned.apk FinalApk.apk


Where FinalApk.apk is the filename of the APK that you will upload to the play store. You can, of course, put the name that you'd prefer.


You're done

Now you have got the APK that you will be able to use and publish on the play store for alpha testing, beta testing or production. I hope this post helped you with the build and signing process and feel free to leave me comments if you have any questions.


Related Posts

14 December, 2016
Fady Soliman
phonegap
138 Views

Did you find this helpfull?

About The Author

Fady Soliman

An experienced, resourceful and highly motivated IT professional, with a proven record of success in both Stack Development and Software Architecture. Possesses a wealth of transferable skills, including outstanding interpersonal, problem solving and staff management abilities. A capable organizer, quick to grasp – and make good use of – new ideas and information, and reliable and conscientious in all he takes on.

leave A Comment