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?
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.
publishing ionic android app..
- Adding platform to project..
ionic cordova platform add android
- Now build the project for release
cordova build android --release
- 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!
- 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.
- 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