Preparing an Apache Cordova Android project for release can seem like a difficult task. The documentation for completing such a task is definitely more than it needs to be.
Let’s go through the full process of creating and building a project for release.
Using the command line with Apache Cordova already installed, run the following commands:
cordova create example com.nraboy.example ExampleProject cd example cordova platform add android
The above commands will create a new project and add the Android platform to it. All Android projects must be signed before release to Google Play. Navigate to platforms/android from the root of your project and run the following:
keytool -genkey -v -keystore example.keystore -alias example -keyalg RSA -keysize 2048 -validity 10000
Fill out all the prompted information after running the above command. More information on creating and using Android keystores can be found in my previous article regarding general Android publishing.
This is where the Apache Cordova documentation might be thin. To avoid having to build, sign, then zipalign we can accomplish all three in one step by doing the following. In the platforms/android directory create a file called ant.properties if it doesn’t already exist. Add the following to the file:
Now when you build with the release tag, your keystore will be used eliminating the need to sign and zipalign manually.
cordova build android --release
The above command will generate ExampleProject-release.apk if you followed my instructions.
A video version of this article can be seen below.