Why does “ionic cordova build” only generate unsig

2019-04-08 11:46发布

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?

2条回答
放我归山
2楼-- · 2019-04-08 12:05

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

查看更多
神经病院院长
3楼-- · 2019-04-08 12:30

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.

查看更多
登录 后发表回答