Powered by Blogger.

Creating A Signed APK File Using CORDOVA- COMMAND LINE INTERFACE


STEP 1: BROWSE TO YOUR APPLICATION DIRECTORY AND RUN COMMAND

root@cheeyu:/home/user/application# 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: like below
<application android:debuggable="false" android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name">
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.

STEP 3: GENERATE OUR RELEASE BUILD:

root@cheeyu:/home/user/application# cordova build --release android
Now you have the unsigned APK file in platforms/android/build/outputs/apk/android-release-unsigned.apk

STEP 4:

KEY GENERATION:

SYNTAX:

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

EGS:

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 the name as NAME-mobileapps.keystore
Note down the password. Keep the password note file and Keystore file safely. For all future versions of the app, you must have to use this Keystore. Otherwise, you will not be able to release future versions of the app which are signed with different Keystore. All app versions must be signed with same Keystore.

STEP 5:

Place the generated Keystore in
old version Cordova
root@cheeyu:/home/user/application/platforms/android/ant-build
New version Cordova
root@cheeyu:/home/user/application/platforms/android/build/outputs/apk
To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

SYNTAX:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore <keystorename <Unsigned APK file> <Keystore Alias name>
root@cheeyu:/home/user/application/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.
in case this step throwing a warning “No -tsa or -tsacert is provided and this jar is not timestamped.”. Fix it by adding “-tsa timestamp.digicert.com” to the command.

STEP 6:

Finally, we need to run the zip align tool to optimize the APK:
root@cheeyu:/home/user/application/platforms\android\ant-build> 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.

No comments