Apache Cordova: Create a signed release APK – Easy HowTo


To upload an app to the Google Play Store, you need to sign it first.

There are a lot of tutorials out there, some of which are simply overwhelming, to say the least.

Here is my very simple solution to create a signed APK which you can upload to the Play Store.

Hate reading? The tl;dr version is at the bottom of the page.

To make it clear: This has been tested with Apache Cordova version 7.0.1.
To check which version of Cordova you are using, run this on your console.

cordova --version

Step 1: Create a keystore file

First: Navigate to your app’s root folder. Then you run the following command, after editing it to suit you environment.

keytool -genkey -v -keystore MyApp.keystore -alias myapp

Here, you will create a keystore file for your project. This file is needed to sign the APK. Simply change the Keystore filename to something you like, and do the same with the alias at the end of the comand.

After hitting enter, you will be presented with a few questions which you need to answer.

After you are done with this, the keystore file will be created in your app’s root directory. Simple move it to the platforms/android  directory.

mv MyApp.keystore platforms/android

Caution

If you do not create the keystore file, your build will crash with the following error message:

FAILURE: Build failed with an exception.

* Where:
Build file '/path/to/your/app/platforms/android/build.gradle' line: 288

* What went wrong:
A problem occurred evaluating root project 'android'.
> Keystore file does not exist: /path/to/your/app/platforms/android/testapp.keystore

Step 2: Create release-signing.properties file

Create a file in your platforms/android/  directory with the name release-signing.properties .

Put the following content into the file

storeFile=YourApp.keystore
storeType=jks
keyAlias=yourapp
keyPassword=YOUR-KEY-PASSWORD
storePassword=YOUR-STORE-PASSWORD

Rename the properties with the ones you provided during your keystore file generation and save the file.

Step 3: Run cordova build

To create your signed APK file, simply run the following command (still in your app’s root directory)

cordova build android --release

Now Cordova will use your release-signing.properties  file and create a signed APK without any hassle.

After the process has finished, you should be presented with something like this:

BUILD SUCCESSFUL

Total time: 3.119 secs
Built the following apk(s):
	/path/to/your/app/platforms/android/build/outputs/apk/android-release.apk

tl;dr : Breaking it down – all in one

Here’s the tl;dr for all the people who don’t want to read all this stuff above.
Replace the options with your own.

  1. keytool -genkey -v -keystore MyApp.keystore -alias myapp
  2. mv MyApp.keystore platforms/android
  3. Create the file platforms/android/release-signing.properties
  4. Insert the following and replace the bold formatted properties with your own
    storeFile=YourApp.keystore
    storeType=jks
    keyAlias=yourapp
    keyPassword=YOUR-KEY-PASSWORD
    storePassword=YOUR-STORE-PASSWORD
    
  5. cordova build android –release

You’re done :)

Extend the validity of the signed APK.

Sometimes while uploading the APK to the Play Store, you get the error which says

You uploaded an APK signed with a certificate that expires too soon. You need to sign your APK with a certificate that expires farther into the future.

So what to do? Well, you create an APK which expires further in the future. To do so, simply add the following to your command

-validity 20000

This will set the expiration of your signature to more than 50 years. So all together, your command now looks like


keytool -genkey -v -keystore MyApp.keystore -alias myapp -validity 20000

Got something to add?

Let me know in the comments :)

Veröffentlicht von

Christian Hänsel

Web-Entwickler, SEO-Experte. Ich liebe technisches SEO, die Entwicklung von neuen Ideen und alles rund um das Internet... ja, ich habe mein Hobby zum Beruf gemacht und gehe auch Montags gerne zur Arbeit.

6 Gedanken zu „Apache Cordova: Create a signed release APK – Easy HowTo“

  1. I’m keep getting this error:

    FAILURE: Build failed with an exception.

    * What went wrong:
    Execution failed for task ‚:app:packageRelease‘.
    > Failed to generate v1 signature

    1. For anyone else having this issue:
      try
      keytool -genkey -v -keystore MyApp.keystore -keyalg RSA -keysize 2048 -validity 90 -alias myapp

      instead of
      keytool -genkey -v -keystore MyApp.keystore -alias myapp -validity 20000

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.