Sunday, 24 April 2016

Create signed APK file using cordova command line interface

Before launching an app into any playstore we need to sign the apk file so that we can claim our copyrights and no one can copy our app or duplicate. If anyone does we can raise a concern with google and claim our copyrights.

Before that you can change the cordova app icon and keep your own logo by replacing the images in the path <ur prj>\platforms\android\res. There are different folders in the path. You need to replace the images in all the folders with same name either screen.png or icon.png

For the app MakeMeWhite (click to download) we launched in playstore I have created the keyfile with the following command.

keytool -genkey -v -keystore ultimateCreations-crazyColors.keystore -alias ultimateCreationsCrazyColors -keyalg RSA -keysize 2048 -validity 10000

<UltimateCreations> is the name which we registered in playstore and <crazycolors> is the name of package of our game. You can use any names as per ur wish.


After clicking enter key fill the following form:

What is the name of your organization?
  [Unknown]:  ULTIMATE CREATIONS
What is the name of your City or Locality?
  [Unknown]:  CHENNAI
What is the name of your State or Province?
  [Unknown]:  TAMILNADU
What is the two-letter country code for this unit?
  [Unknown]:  IN
Is CN=ULTIMATE CREATIONS, OU=ULTIMATE CREATIONS, O=ULTIMATE CREATIONS, L=CHENNAI, ST=TAMILNADU, C=IN correct?
  [no]:
What is your first and last name?
  [ULTIMATE CREATIONS]:  ULTIMATE CREATIONS
What is the name of your organizational unit?
  [ULTIMATE CREATIONS]:  APPDEV
What is the name of your organization?
  [ULTIMATE CREATIONS]:  ULTIMATE CREATIONS
What is the name of your City or Locality?
  [CHENNAI]:
What is the name of your State or Province?
  [TAMILNADU]:
What is the two-letter country code for this unit?
  [IN]:
Is CN=ULTIMATE CREATIONS, OU=APPDEV, O=ULTIMATE CREATIONS, L=CHENNAI, ST=TAMILNADU, C=IN correct?
  [no]:  y

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
        for: CN=ULTIMATE CREATIONS, OU=APPDEV, O=ULTIMATE CREATIONS, L=CHENNAI, ST=TAMILNADU, C=IN
Enter key password for <ultimateCreationsCrazyColors>
        (RETURN if same as keystore password):
Re-enter new password:

[Storing ultimateCreations-crazyColors.keystore]



Now the key file is successfully generated in the path in which u have ran the commands.
Place the key file generated in the path where apk file is generated.
(C:\<ur cordova prj>\platforms\android\build\outputs\apk)


Now run the command to generate release build

D:\projects\Phonegap\Example> cordova build --release android
Now run the command in the path C:\<ur cordova prj>\platforms\android\build\outputs\apk

jarsigner -tsa http://timestamp.digicert.com -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ultimateCreations-crazyColors.keystore android-release-unsigned.apk ultimateCreationsCrazyColors

Finally, we need to run the zip align tool to optimize the APK:

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



Enjoy...................!

No comments:

Post a Comment