If you’re using Cordova 5.x+, it’s easy to configure it to also build signed release builds of your Android application. Providing you’ve already created a
keystore using the
keytool, this tutorial will have you building release builds in minutes, using the
cordova build command.
Before you start, you’ll need to create a
keystore that will be used to sign the application. This can be done using the keytool that comes with Java.
$ keytool -genkey -v -keystore app.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
This will create a keystore called
app.keystore, with alias
alias_name. It will be valid for 10,000 days (~27 years). You will be prompted to enter a password to secure the keystore and alias.
Make a note of all the details you’ve used as we’ll need it to setup signing in Cordova.
Next, we need to create the configuration file Cordova will use to sign your release build. This is done by creating the
release-signing.properties file in the
platforms/android folder of your app.
In this file, you’ll need to add the following:
Each of the variables must match the details you used when creating the keystore (or in the Prerequisites step). If you didn’t enter passwords for the keystore (
storePassword) or alias (
keyPassword), these lines can be removed from the file.
Building and Signing
When you’re ready to build and sign your app, you can simply run the following Cordova command:
cordova build android --release
If the build is successful, the
android-release.apk file will be generated in the
platforms/android/build/outputs/apk folder. Keep an eye on the output to see if the build was successful, and to find the location of the file.
The above screenshot has been modified to hide intermediate output from the build process, and to redact confidential information.
If the file wasn’t setup correctly, or the changes didn’t take affect, the
android-release-unsigned.apk file will be generated instead, indicating that the APK wasn’t signed. If this happens, try cleaning the build using
cordova clean android, and trying again