I want to sign an apk file using keytool , I have a public certificate .cer file and a private key .pem I used to use the android studio wizard to sign apk , now I have no idea how to do it.
Asked
Active
Viewed 3,012 times
1 Answers
3
You can't sign an APK with keytool
.
You can use jarsigner
(doc) or apksigner
(doc).
I highly recommend you sign with the latter (apksigner), since it has additional protections, is faster and is the recommended approach by the Android team.
apksigner
is distributed via the SDK Build tools which you can download using the SDK Manager.
Then, the command line is:
apksigner sign --ks keystore.jks app.apk
where:
- "keystore.jks" is the path to your keystore.
- "app.apk" is the path the APK you want to sign.
You'll be prompted to enter the key alias from the keystore, then the password of the keystore and the password of the key. You can also enter those values on the command line if need be, e.g.
apksigner sign --ks keystore.jks --ks-key-alias AndroidDebugKey --ks-pass pass:android app.apk

Pierre
- 15,865
- 4
- 36
- 50
-
Thx for your answer, I know that I have to sign it using apksigner, I mentioned keytool cos I have the private key and the public certificate, so I was wondering how should I create keystore with an alias (using private key and keytool ) – Anass Boukalane Aug 04 '20 at 16:16
-
Have you looked at this answer? https://stackoverflow.com/questions/906402/how-to-import-an-existing-x-509-certificate-and-private-key-in-java-keystore-to – Pierre Aug 04 '20 at 16:49
-
I did but i don’t know the right way , there is a lot of ways I guess and I have pem file as private key and cer file as public key. – Anass Boukalane Aug 04 '20 at 17:04
-
My problem is how to create a keystore using the private key (pem file) and the public key (cer file) – Anass Boukalane Aug 04 '20 at 21:58