5

I use the below command in order to generate a signed APK, I'm pretty sure this worked a few months ago:

$ ionic cordova build android --prod --release --keystore="./my-keystore-file.keystore" --storePassword=mypass --alias=mymail@gmail.com --password=mypass

However, only an unsigned APK is generated. How can I generate a signed APK using ionic?

Dave Bauman
  • 9,252
  • 1
  • 19
  • 19
Jas
  • 14,493
  • 27
  • 97
  • 148

2 Answers2

8

You need to include -- -- before the Cordova-specific arguments:

$ ionic cordova build android --prod --release -- -- --keystore="./my-keystore-file.keystore" --storePassword=mypass --alias=mymail@gmail.com --password=mypass

The build android --prod --release options are handled by the Ionic CLI, whereas everything after the first -- is passed to the Ionic Cordova plugin. Then everything after the 2nd -- is passed to Cordova itself.

Dave Bauman
  • 9,252
  • 1
  • 19
  • 19
  • cool!!! i didn't see this or I just skipped seeing this!! will check it as soon as my `ionic` command does not `freeze` for some reason just running it and it's freezing. so will mark as resolved hopefully once the command line is back to work. – Jas May 23 '17 at 09:24
  • 1
    I couldn't find this anywhere in the documentation, I guess it hasn't been updated since the switch to plugins in version 3.0. I had to dig into the source code to discover this. – Dave Bauman May 24 '17 at 16:55
  • 1
    THANK YOU! Tonight would otherwise have been a very long night :] – Daniel Shin Jul 06 '17 at 15:47
0

publishing ionic android app..

  1. Adding platform to project..

ionic cordova platform add android

  1. Now build the project for release

cordova build android --release

  1. We can find our unsigned APK file in platforms/android/build/outputs/apk. Now, we need to sign the unsigned APK.

Let’s generate our private key using the keytool command that comes with the JDK.

keytool -genkey -v -keystore <name_of_keystore>.keystore -alias alias_name 
-keyalg RSA -keysize 2048 -validity 10000

enter password for the keystore file. remeber this password, it will be useful in future.after entering all fields, it will generate a keystore file. save copy of it somewhere else for future use.if you lose it you won’t be able to submit updates to your app!

  1. To sign the unsigned APK, run the jarsigner tool which is also included in the JDK:

jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore name_of_keystore.keystore path_to_unsigned_apk_file.apk alias_name

for easy use, copy unsigned to apk to project's root and just use filename.apk in place of path.

it will ask us to enter the keystore password.

  1. Finally, we need to run the zip align tool to optimize the APK

zipalign -v 4 HelloWorld-release-unsigned.apk new_apk_name.apk

Now we have our final release binary called HelloWorld.apk and we can release this on the Google Play Store.

source: ionic docs

varun aaruru
  • 2,920
  • 1
  • 20
  • 36
  • but i used this one-liner from here: https://forum.ionicframework.com/t/releasing-ionic-2-app-on-android/46116/3 – Jas May 19 '17 at 11:01
  • I think that works if you already have a keystore file..I have not tried that way.. – varun aaruru May 19 '17 at 11:02
  • i already have a keystore this one liner already worked for me, it just stopped and now generates only usnigned but it already was working fine same command 2 months ago this is why i was wondering why its not working anymore.. – Jas May 19 '17 at 11:03
  • yes I have just tested it and it is working perfectly fine..if you see the above answer.. the command you provided is doing work upto step3. so it will release only unsigned apk.. I am wondering how it will generate signed apk without jarsigner and zip align tools – varun aaruru May 19 '17 at 11:13