Maxim Maxim - 1 month ago 4
Android Question

Specify signing config for Gradle and Cordova 5

In correspondence with Cordova news version 5.0.0 is ready. I tried to upgrade all my Android projects like it was usually.

To update Cordova framework itself:

npm update -g cordova

To update library in Android project:

cordova platform update android

After building new version using "--release" option:

cordova build android --release

I got only unsigned version. Strange...

So how is it possible to reuse existing keystore (previously generated by keytool and used by Cordova 4.0.0) to get signed APK?


It looks like Cordova 5.0.0 uses Gradle build automation system instead of Ant. So original settings for keystore defined in the file "/platforms/android/" will not be used during building. So we will get unsigned APK as a result.

To solve this issue we need to tell Gradle to use existing keystore as well. Investigation of build.gradle gives us useful information that we need to provide signingConfigs.

But it is bad idea to do that in this file because it is labelled as auto-generated and it should be free of any editing.

So finally I have found the way to solve it. Object "signingConfigs" will be constructed from file with filename stored in cdvReleaseSigningPropertiesFile. In correspondence with documentation the default value of this variable is "". So we need just to create new file with such name in the same folder as "build.gradle" file and put inside the following content:

// if you don't want to enter the password at every build, you can store it with this

Path in example is specified for keystore saved in the project root directory. It has Windows style... In case of Linux you will need to use single slashes (not double backslashes like in above example).

In addition you can set your own path for signing settings file. To read more about that check the edge version of cordova documentation.