Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 494
Maxim Avatar asked May 07 '15 16:05

Maxim


People also ask

How do I set Gradle properties in Cordova?

By using the --gradleArg flag in your Cordova build or run commands: By placing a file called gradle.properties in your Android platform folder ( <your-project>/platforms/android) and setting the properties in it like so: By extending build.gradle via a build-extras.gradle file and setting the property like so:

How do I sign a package using Gradle?

Now create a file name myproject.gradle in /home/username/.signing (create the folder if necessary). This file will contain your signing config, that should be used to sign the package. This could look like the following: For more information on the signing configuration for android read their documentation.

Does Cordova 5 use ant or Gradle?

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/ant.properties" will not be used during building. So we will get unsigned APK as a result.

How do I add an external configuration to a Gradle file?

The simplest and cleanest way to add an external configuration is through a separate Gradle file apply from: './keystore.gradle' android { signingConfigs { release { storeFile file (keystore.storeFile) storePassword keystore.storePassword keyAlias keystore.keyAlias keyPassword keystore.keyPassword } } }


1 Answers

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/ant.properties" 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 "release-signing.properties". 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:

storeFile=..\\..\\some-keystore.keystore storeType=jks keyAlias=some-key // if you don't want to enter the password at every build, you can store it with this keyPassword=your-key-password storePassword=your-store-password 

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.

like image 59
Maxim Avatar answered Oct 02 '22 12:10

Maxim