Signing apk works from Android Studio but why the same keystore do not work on command line?

3.2k views Asked by At

My key for signing Android app was generated using Android Studio. It is working fine when I try to generate signed APK from Android Studio.

However the same key is not working when I try to sign using apksigner tool. Here is the command I am using.

apksigner sign --ks mykey.jks --ks-key-alias MyAlias --out app-myapp-release.apk app-myapp-release-aligned.apk

I am getting below errors:

java.io.IOException: Keystore was tampered with, or password was incorrect

Any suggestions?

** Update ** Android Studio Version 2.2.3 The keystore was generated using "Generate Signed APK" dialog box from Build menu.

2

There are 2 answers

4
Nemanja Kovacevic On BEST ANSWER

I just had this exact problem, and many more while trying to sing an apk.

Try to add these options to your sign command:

--ks-pass stdin  --key-pass stdin

Now you can normally type in your keystore password and your key (alias) password in that order.

5
Soufiane ROCHDI On

(I cannot write comments) so I added this as answer and hope this will help you with your issue. Did you check these links:

Just for information: Your JKS file should contain the private key and the certificate meant to sign the APK, here is the official link for more details.