วันพุธที่ 29 เมษายน พ.ศ. 2558

Publish Android PhoneGap application

After I have finished developing my application. I'd to publish application to APK file for sending to GooglePlay. Now here my development, I use Macbook Air  OSX 10.9.5 , Netbean IDE coding  on  HTML5, AngularJS, OnsenUI, JavaScript, test application Ripple Emulator.

You should have  PhoneGap directory like : config.xml  hooks platforms plugins www. You have to

=> 1. Build Application by PhoneGap
=> 2. Point Android SDK path
=> 3. Create KeyStore file
=> 4. Sign App with Keystore
=> 5. Final APK file with Zip Align

you will get APK file and this file can upload to google play.


Step 1 : open terminal Goto Phonegap Root Document that contains some folders like this


 config.xml  hooks platforms plugins www


Step2 : terminal  : 

phonegap build android
You will get android folder in platforms folder. Now you have to disable debug mode by goto finder and goto : platform -> android open file  AndroidManifest.xml with text editor and add 


ADD  android:debuggable="false" to 

<application android:debuggable="false"



step3 : back to Terminal again and change folder to cordova ant-build

cd platforms/android/ant-build

step4 : Point android SDK tool location folder , if you don't know where is it, please find its your way.

export ANDROID_HOME=/usr/local/Cellar/android-sdk/24.1.2

hit enter and

export PATH=$ANDROID_HOME/tools:$PATH

step5 : Create Keystore, you can change app name "samma.keystore" to your app's name and "samma" the alias name you can change to any you desire.

keytool -genkey -v -keystore samma.keystore -alias samma -keyalg RSA -keysize 2048 -validity 10000


and create password and answer question.

You will get the samma.keystore in present folder that is : samma/platforms/android/ant-build

The Keystore, you have to keep this file, don't lose it, in case you want to build new app version. If you upload APK to GooglePlay that sign with this key, you have to upload new version app that sign with the same key.


step6 : Up 1 level directory and goto samma/platforms/android/cordova/ for Compiling Codova by

cd ../cordova/

and RUN

cordova build android --release

Now you will get file : CordovaApp-release-unsigned.apk in /ant-build



step7 : Change folder to ant-build where the Keyfile and APK file are created 

cd ../ant-build

and Sign the appkey with Keystore file that just created by run

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore samma.keystore CordovaApp-release-unsigned.apk samma


Don't forget to change name of keystore file and samma alias_name

if done, You will get the same filename CordovaApp-release-unsigned.apk but this file is already signed. 


step8 : zip align with zipalign tool , samma_ok.apk is final file.

/usr/local/Cellar/android-sdk/24.1.2/build-tools/22.0.1/zipalign -f -v 4 CordovaApp-release-unsigned.apk samma_ok.apk




And now you can upload samma_ok.apk to Google Play