user12920
user12920

Reputation: 301

how do i add my certificate to cordova when building an app?

How do I compile my apps with my developer certificate keys when using cordova from the command line?

By default it uses a debug certificate key, how do I use the one that I use when i'm building using the online phonegap build tool?

Upvotes: 0

Views: 4146

Answers (1)

cfprabhu
cfprabhu

Reputation: 5352

  1. Remove the console plugin:

    D:\projects\Phonegap\Example> cordova plugin rm org.apache.cordova.console
    
  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 "android:debuggable" to "false".

  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.

  4. Note: you want to create key, please proceed with the following steps.

    Key Generation Syntax:

    keytool -genkey -v -keystore .keystore -alias -keyalg -keysize -validity
    

    Examples:

    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? : xx
    

    Then the Key store has been generated with name as NAME-mobileapps.keystore

  5. Place the generated keystore in D:\projects\Phonegap\Example\platforms\android\ant-build

    To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

    jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore
    

    Example:

    D:\projects\Phonegap\Example\platforms\android\ant-build> 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.

  6. Finally, we need to run the zip align tool to optimize the APK. Run either of the following:

    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
    

    Now we have our final release binary called example.apk and we can release this on the Google Play Store.

Upvotes: 3

Related Questions