Thursday, 15 December 2016


how to create signed APK file using cordova command line interface:

Step 1:

D:\projects\Phonegap\Example> cordova plugin rm org.apache.cordova.console --save
add the --save so that it removes the plugin from the config.xml file.

Step 2:

To generate a release build for Android, we first need to make a small change to the AndroidManifest.xml file found in platforms/android. Edit the file and change the line:
<application android:debuggable="true" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
and change android:debuggable to "false":
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
As of cordova 6.2.0 remove the android:debuggable tag completely. Here is the explanation from cordova:
Explanation for issues of type "HardcodedDebugMode": It's best to leave out the android:debuggable attribute from the manifest. If you do, then the tools will automatically insert android:debuggable=true when building an APK to debug on an emulator or device. And when you perform a release build, such as Exporting APK, it will automatically set it to false.
If on the other hand you specify a specific value in the manifest file, then the tools will always use it. This can lead to accidentally publishing your app with debug information.

Step 3:

Now we can tell cordova to generate our release build:
D:\projects\Phonegap\Example> cordova build --release android
Then, we can find our unsigned APK file in platforms/android/ant-build. In our example, the file was platforms/android/ant-build/Example-release-unsigned.apk

Step 4:

Note : We have our keystore 'keystoreNAME-mobileapps.keystore' in this Git Repo, if you want to create another, please proceed with the following steps.

Key Generation:


keytool -genkey -v -keystore <keystoreName>.keystore -alias <Keystore AliasName> -keyalg <Key algorithm> -keysize <Key size> -validity <Key Validity in Days>


keytool -genkey -v -keystore NAME-mobileapps.keystore -alias NAMEmobileapps -keyalg RSA -keysize 2048 -validity 10000

keystore password? : xxxxxxx
What is your first and last name? :  xxxxxx
What is the name of your organizational unit? :  xxxxxxxx
What is the name of your organization? :  xxxxxxxxx
What is the name of your City or Locality? :  xxxxxxx
What is the name of your State or Province? :  xxxxx
What is the two-letter country code for this unit? :  xxx
Then the Key store has been generated with name as NAME-mobileapps.keystore

Step 5:

Place the generated keystore in
old version cordova D:\projects\Phonegap\Example\platforms\android\ant-build
New version cordova D:\projects\Phonegap\Example\platforms\android\build\outputs\apk
To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:


jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename <Unsigned APK file> <Keystore Alias name>


D:\projects\Phonegap\Example\platforms\android\ant-build> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore Example-release-unsigned.apk xxxxxmobileapps
OR D:\projects\Phonegap\Example\platforms\android\build\outputs\apk> jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore Example-release-unsigned.apk xxxxxmobileapps
Enter KeyPhrase as 'xxxxxxxx'
This signs the apk in place.

Step 6:

Finally, we need to run the zip align tool to optimize the APK:
D:\projects\Phonegap\Example\platforms\android\ant-build> zipalign -v 4 Example-release-unsigned.apk Example.apk 
D:\projects\Phonegap\Example\platforms\android\ant-build> C:\Phonegap\adt-bundle-windows-x86_64-20140624\sdk\build-tools\android-4.4W\zipalign -v 4 Example-release-unsigned.apk Example.apk
D:\projects\Phonegap\Example\platforms\android\build\outputs\apk> C:\Phonegap\adt-bundle-windows-x86_64-20140624\sdk\build-tools\android-4.4W\zipalign -v 4 Example-release-unsigned.apk Example.apk
Now we have our final release binary called example.apk and we can release this on the Google Play Store.

Step by Step Tips   :

(1)tell cordova to generate our release build:

cordova build --release

(2)Key Generation:

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

(note: NAME-mobileapps.keystore is keystore name and NAME-mobileapps is alias name and kyesize is 20148 and validity is 10000)


cordova run android --release -- --keystore=NAME-mobileapps.keystore --storePassword=om@1234 --alias=NAME-mobileapps.keystore --password=om@1234

(3)Place the generated keystore in

old version cordova D:\projects\Phonegap\Example\platforms\android\ant-build

New version cordova D:\projects\Phonegap\Example\platforms\android\build\outputs\apk

D:\projects\Phonegap\Example\platforms\android\build\outputs\apk>jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore android-release-unsigned.apk NAME-mobileapps


jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore NAME-mobileapps.keystore android-release-unsigned.apk NAME-mobileapps

Enter KeyPhrase as 'xxxxxxxx'

here keyPhrase is your password of keystore.

Check your keystore alias name once. Some times keystore alias name is different from keytool alias name then it gives the  error...So check it alias names once)

(5)zipalign -v 4 Example-release-unsigned.apk Example.apk  (Note: first set path="D:\om\Android development detials\android-sdk-windows\build-tools\24.0.0")

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


D:\phpnotes\platforms\android\build\outputs\apk>set path="D:\om\Android developm
ent detials\android-sdk-windows\build-tools\24.0.0"

D:\phpnotes\platforms\android\build\outputs\apk>zipalign -v 4 android-release-un
signed.apk omsir.apk

Saturday, 10 December 2016

Android – WebViewClient example:

Android –  WebViewClient  example:
 What is WebViewClient and what is it’s usage?
When the user clicks a link from a web page in your WebView, the default behavior is for Android to launch an application that handles URLs. Usually, the default web browser opens and loads the destination URL. However, you can override this behavior for your WebView, so links open within your WebView. You can then allow the user to navigate backward and forward through their web page history that’s maintained by your WebView.
To open links clicked by the user, simply provide a WebViewClient for your WebView, using setWebViewClient().
Demo of creating an application to open any URL inside the application and clicking on any link from that URl
should not open Native browser but that URL should open in the same screen.

(1)write    code  for  file  :

import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;

 * Demo of creating an application to open any URL inside the application and clicking on any link from that URl
should not open Native browser but  that URL should open in the same screen.
public class MainActivity extends Activity {
/** Called when the activity is first created. */

WebView web;

public void onCreate(Bundle savedInstanceState) {

web = (WebView) findViewById(;
web.setWebViewClient(new myWebClient());

public class myWebClient extends WebViewClient
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);

public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub

return true;


// To handle "Back" key press event for WebView to go back to previous screen.
public boolean onKeyDown(int keyCode, KeyEvent event)
if ((keyCode == KeyEvent.KEYCODE_BACK) && web.canGoBack()) {
return true;
return super.onKeyDown(keyCode, event);

(2)write  code for  activity_main.xml file:
<?xml version="1.0" encoding="utf-8"?>




    xmlns:tools="" android:layout_width="match_parent"

    android:layout_height="match_parent" android:fitsSystemWindows="true"


    < android:layout_height="wrap_content"

        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

        < android:id="@+id/toolbar"

            android:layout_width="match_parent" android:layout_height="?attr/actionBarSize"

            android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" />


    <include layout="@layout/content_main" />

    < android:id="@+id/fab"

        android:layout_width="wrap_content" android:layout_height="wrap_content"

        android:layout_gravity="bottom|end" android:layout_margin="@dimen/fab_margin"

        android:src="@android:drawable/ic_dialog_email" />


(3)Write   code for conent_main.xml file:
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android=""


    xmlns:app="" android:layout_width="match_parent"

    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"





    tools:showIn="@layout/activity_main" tools:context=".MainActivity">

    <TextView android:text="Hello World!" android:layout_width="wrap_content"

        android:layout_height="wrap_content" />









Recent Posts

Powered by Blogger.


About Me

My Photo
B.E.(COMPUTER ENGINEER) PHP Web developer & Provide Training for Web Development , Digital Marketing ,Android Mobile Apps Development


© 2013 ANDROID TRAINING IN MUMBAI BY OM SIR. All rights resevered. Designed by Templateism

Back To Top