Sign Android build with Cordova 5

Change the android apk signing mechanism, based on updates in Cordova 5

Posted by Aditya Pratap Singh on March 16, 2016

The way we used to sign a Cordova/Ionic android build was to create a keystore and and the keystore, passwords to an ant.properties files as mentioned here .

But with the new version 5 of Cordova and onwards, it has changed and the new steps require the keystore to be specified as command-line variables or as a config file.

The steps to sign the new way are:

  1. Add a keystore using:
    keytool -genkey -v -keystore example.keystore -alias example -keyalg RSA -keysize 2048 -validity 10000 
    Note: This should be at root of project. Though not a hard requirement, it eases the file referencing

  2. Add a build.json with release/dev configuration for keystore, at the root of project:
    
    {
       "android": {
           "debug": {
               "keystore": "..\android.keystore",
               "storePassword": "android",
               "alias": "mykey1",
               "password" : "password",
               "keystoreType": ""
           },
           "release": {
               "keystore": "..\android.keystore",
               "storePassword": "",
               "alias": "mykey2",
               "password" : "password",
               "keystoreType": ""
           }
       }
    }
    

  3. Add the --buildConfig switch to Cordova/ Ionic build command:
    cordova build android --release --buildConfig=build.json
    or with Ionic as
    ionic build android --release --buildConfig=build.json

  4. The signed file will be generated under the new folder structure at
    /platforms/android/build/outputs/apk/android-release.apk