Unable to use ionic cordova run android --prod --release

When trying to run ionic cordova run android --prod --release I get the following error


Sign the build using '-- --keystore' or '--buildConfig' or sign and deploy the unsigned apk manually using Android tools.

[ERROR] An error occurred while running cordova run android --keystore=platforms/android/keystore/my-release-key.jks 
        --s... (exit code 1).

I was able to manually build an unsigned .apk and then sign it using jarsigner and zipalign as per https://ionicframework.com/docs/intro/deploying/

However I would like to know what steps do I need to take so that the run command executes correctly?

I use Android Studio for creating final apk builds by Build > Generate Signed APK … - had no problems this way

I also have no problem in generating the signed .apk builds using the manual method, however I was wondering if I would be able to get ionic cordova run android --prod --release to work

1 Like

yeah, same problem here :slight_smile:

1 Like

What i’ve done, and what I believe to still be in good/decent practice(?), is create a build.json file at the root of my project and fill it with:

    "android": {
        "release": {
            "keystore": "name-of-your.keystore",
            "storePassword": "super-awesome-password",
            "alias": "alias you entered in your keystore",
            "password" : "super-awesome-password",
            "keystoreType": "JKS"

Then you can run ionic cordova build android --prod --release and it’ll sign and zipalign it.

Alternatively, based on the message you’re getting, I’d imagine you can do:
ionic cordova build android --prod --release -- --keystore name-of-your.keystore and it’ll ask for all this information. Though I haven’t tested this theory yet.


Absolutely correct @SigmundFroyd.

The Cordova CLI options are documented here: https://cordova.apache.org/docs/en/7.x/guide/platforms/android/index.html#signing-an-app
Examples for Ionic CLI are here:

1 Like

There are two steps which you have to follow:
Step1. delete module.js in your pages
Step2. remove the @ionicpage() from your .ts