unable to sign the unsigned APK
Solution 1
You need to remove the -
in front of the keystore
file and add the flag -keystore
:
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore F:\mobile\moto\whatever_the_path_is_to_your_apk_file\HelloCordova-release-unsigned.apk alias_name
Generally I use these commands to generate a release build apk
that I will publish in the Google Play Store:
cd ~/Projects/myappname/
cordova build android --release
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore certificates/myappname-cert.keystore -storepass myappname -keypass myappname platforms/android/ant-build/CordovaApp-release-unsigned.apk myappname
jarsigner -verify -verbose -certs platforms/android/ant-build/CordovaApp-release-unsigned.apk
~/android-sdk-macosx/build-tools/21.1.2/zipalign -v 4 platforms/android/ant-build/CordovaApp-release-unsigned.apk releases/android/myappname1.0.0.apk
Note that I created the dir. certificates
with the .keystore certificate, and the dir. releases/android
where I save all signed apk releases.
To generate a new keystore
file with a new password
:
keytool -genkey -v -keystore certificates/my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000
Solution 2
Steps to sign Corodva apk using keytool, jarsigner and zipalign are:
1. Generate keystore for your app using keytool:
keytool -genkey -v -keystore android.keystore -alias android_app -keyalg RSA -keysize 2048 -validity 10000
2. Next create a certificate into a pkcs12 keystore format with keytool
keytool -importkeystore -srckeystore android.keystore -destkeystore android.keystore -deststoretype pkcs12
It will create two files in Project_root_dir as android.keystore (with pkcs12) and android.keystore.old (without pkcs12)
3. Sign apk with jarsigner:
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore android.keystore app-release-unsigned.apk android_app
First time you'll get below error as:
jarsigner: unable to open jar file: app-release-unsigned.apk
Then you just need to move .apk file from
/Project_root_dir/platforms/android/app/build/outputs/apk/release/app-release unsigned.apk
in to Project_root_dir/
Then again run the jarsigner command above, it will sign apk successfully.
4. Finally verify apk:
zipalign -v 4 app-release-unsigned.apk app-release.apk
Your apk is signed successfully, you can publish it in play store.
I hope this will help you.
syareen
Updated on June 24, 2022Comments
-
syareen almost 2 years
I'm trying to sign the unsigned APK. I followed this link.
My steps:
-
$ cordova build --release android
(success) -
$ keytool -genkey -v -keystore my-release-key.keystore -alias alias_name - keyalg RSA -keysize 2048 -validity 10000
(success) -
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore HelloWorld-release-unsigned.apk alias_name
(got problem)
The problem is:
jarsigner: unable to open jar file: HelloWorld-release-unsigned.apk
Then i followed this link.
-
$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -my-release-key.keystore F:\mobile\moto\whatever_the_path_is_to_your_apk_file\HelloCordova-release-unsigned.apk alias_name
(got problem)
the problem is:
Illegal option: -my-release-key.keystore
Can anyone help me. Thank you.
-
-
syareen about 8 yearswhen i use this by removing the
-
=$ jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 my-release-key.keystore F:\mobile\moto\whatever_the_path_is_to_your_apk_file\HelloCordova-release-unsigned.apk alias_name
it telling methe only one alias can be specified
-
syareen about 8 yearsThen i tried this
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore -storepass try -keypass try C:\Users\Users\desktop\try\platform\android\build\outputs\apk\android-release-unsigned.apk try
it telling mejarsigner error: java.lang.RuntimeException: keystore load: keystore was tempered with, or password was incorrect
-
manzapanza about 8 yearsI updated my answer adding the command to generate a new one keystore file with a new password.
-
syareen about 8 yearsBefore this I'm using this
c:\Users\Users\desktop\try\platform\android\build\outputs\apk\android-release-unsigned.apk
then I changed intoplatform\android\build\outputs\apk\android-release-unsigned.apk
just like you did. Then its working thanks for advanced :)