Android Studio: cannot recover key
Asked Answered
C

20

126

I have searched StackOverflow for a while, but I just wanted to make sure...

I wiped my laptop a while ago, and backed up all my files. I have my android.jks file backed up, and it's back in place. When I try to generate a signed APK, it's giving me the same dreaded error everyone is getting:

Error:Execution failed for task ':app:packageRelease'.
> Failed to read key conjugationappkey from store     
"/Users/wasimsandhu/android.jks": Cannot recover key

I have my android.jks, the key password, the key store password. Everything is correct. What am I missing? I backed up all of my files, so if there is a specific file I need, I could find it, but I have no idea what to do...

If I'm not making any sense, please ask me to clarify. Thanks!

Clamorous answered 2/5, 2015 at 2:25 Comment(2)
If you've used character & or @ in your keystore password, then don't scroll down to the answer section, jump to this link, for sharma's answer.Legaspi
CROSS CHECK YOUR KEYPASSWORD FOR ANY SPELLING CORRECTION . FOR ME I ACCIDENTLTY MISSPELLED ITPredella
C
140

I'm not surprised this didn't gain any traction, but here is what I did for anyone who stumbles onto this post.

As I said, all of my files were backed up. I restored the android.jks file from an older backup. Then, I opened a Terminal window and typed in the following:

keytool -storepasswd -new [insert new keystore password] -keystore [insert keystore file name]

keytool -keypasswd -alias [insert alias] -new [insert new key password] -keystore [insert keystore file name]

The keystore and key passwords have to be the same! This fixed my problem, and I hope it helps you too.

Clamorous answered 5/5, 2015 at 0:32 Comment(19)
Thank you! How did you found out that the passwords have to be the same? I started getting this error today. Until now everything worked well with two different passwords.Parley
Same with me. The issue started from one day to another! I did'nt use old backup files... It just happend.Brandie
My passwords are same and I still got this error. I was able to sign previous version with the same key. Now what should I do?Chiro
Any news? This isn't working for me, still getting cannot recover key errorRoshelle
I just signed an apk with different passwords?Wyly
I have been facing the same issue. The day before yesterday I have successfully generated signed APK and today again the same issue. Can any one have a permanent solution!Dacia
Its giving this error still now in my case: "keytool error: java.security.UnrecoverableKeyException: Cannot recover key"Crankle
For me too, the same problem. after executing the first line, it asks for a password. I give it but then it says "keytool error...keystore was tampered with or password was incorrect"Bedwarmer
I have been facing same issue.Pulsometer
On running the first line of code I am getting the following error - "keytool error: java.security.UnrecoverableKeyException: Cannot recover key" In my case both the keystore and alias password are different.Butter
@KavinRajuS I encountered this error until I changed the key not to use any special character. I had a $ in the key password which triggered the error. Try running the second line firstFelicitasfelicitate
Not working. Following error showing keytool error: java.security.UnrecoverableKeyException: Cannot recover keyEtem
Interesting how it's explicitly mentioned in Android documentation that these two passwords should be differentKauslick
Have same issue here. Anyone has a solution?Patric
I faced the same problem then i used alpha numeric password without including special characters and it worked. Thanks.Cloddish
Your answer is incorrect: first of all passwords should be different and second of all the problem is that you didn't typed password for key correctly.Precautionary
'keytool' is not recognized as an internal or external command, operable program or batch file!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!Ardeen
This is a known bug on Android Studio 4.2 any idea how to fix this?Jacelynjacenta
extracted password from .jks with brutal force process and then followed this process and now apk is uploaded to playstore. This really helped.Redan
Q
75

[Update: This no longer works in Android studio 3.0 and above]

I faced the similar problem and none of the solutions worked after wasting 3 hours on Internet, I decided to dig deep.

Here is how I solved it: The "Cannot recover key" error for me was because my "Keystore password" was correct but the "Key Password" (of the key alias) was incorrect. I was pretty sure the both passwords were same but to my dismay they weren't and I didn't know what the second password was. As I had already signed an APK before I checked out the log file which can be found:

  • C:\Users\your_username\.AndroidStudio2.1\system\log\

Open the log files from the date which you had signed the apk and look for the following entries:

 INFO - .project.GradleExecutionHelper - Passing command-line args to Gradle Tooling API: [--configure-on-demand, -Pandroid.injected.invoked.from.ide=true, 
-Pandroid.injected.signing.store.file=E:\HobbyProjects\XYZProject\gpsjs.jks, 
-Pandroid.injected.signing.store.password=***KeyStorePassword***, 
-Pandroid.injected.signing.key.alias=***alias_name***, 
-Pandroid.injected.signing.key.password=***Key password***, 

And you will find the passwords in plain text. This will even work if you forget passwords.

Qualifier answered 31/7, 2016 at 17:9 Comment(11)
YES! FINALLY! My password was in the "idea" file inside the folder you mentioned. I even tried using a password cracker but it gave me the Alias pass and I though it was the keystore's, but it wasn't.Lepido
Thanks! I was using the master password that I entered when signing the apk, but I just needed to repeat the key password.Abridgment
I had never seen a log file. To check log files provides me a very strong clue. Thank you.Ambrosial
OMG LOVE YOU MAN; you saved my life, Lol, for me was because i just updated Android Studio so my password was lostedSyllabify
Does this work for AndroidStudio3.0? I am seeing my passwords as *********.Tripody
thank you man. you saved my day! I'm using macOs so you can find log by click on help menu and choose show log in finder option.Kareenkarel
My both Keystore passord and Key password are the same. Since I updated my Android Studio to verion 3.3 - signing the app does not work.Downall
My file says: -Pandroid.injected.signing.store.password=*********, -Pandroid.injected.signing.key.alias=mykey, -Pandroid.injected.signing.key.password=*********Trait
@Trait Android studio team fixed this loophole in the recent versions.Qualifier
Just to be sure, does that mean that you were incorrect and that both passwords weren't the same?Prokopyevsk
@WouterVandenputte Yes, I tried to copy paste the passwords while creating the key and some random text on clipboard got pasted for the second password.Qualifier
G
36

If it can help anyone - the problem in my case was that the "Key store password" and "Key password" were incorrect.

Glory answered 29/9, 2016 at 9:25 Comment(1)
Your password should be marked as the correct onePrecautionary
O
22

I tried all given suggestions in answers and comments :(

My key password and keystore password are exactly the same. Using android studio 3.4

What worked for me was force quit Android Studio, start again, clean and rebuild project and then generate signed apk. all configs exactly the same but it worked this time

Octahedral answered 9/5, 2019 at 9:8 Comment(3)
I cleaned and rebuilt the project and then it worked fine. +1 upCurson
This worked for me. Not a cool "feature" for an IDE to mess up management of crucial information like that.Favien
Confirmed in Android Studio 3.6.2 P.S. I love youMutant
H
12

[Android Studio 3.3] I got the 'cannot recover key' error on generating a signed APK. I was able to check in an older idea.log for the correctness of my password: Key Store and Key passwords were identical and correct.

Updating the key password in the terminal:

keytool -keypasswd -alias MYKEY -keystore KEYSTORE

It seems to be no longer possible to have identical passwords for keystore and key. The keytool gave me an error, when I tried. After setting a different password for the key, Android Studio generated a signed APK.

Maybe, in previous Android Studio versions passwords had to be identical - now it may be the opposite.

Hunk answered 2/2, 2019 at 17:32 Comment(2)
I updated my app 2 weeks ago, and today won't work. I use this to change the passwords to be the same and updated the Android Studio, now I realeased a new version.Zandra
Between @Build3r's answer and this one, I was able to set both passwords to different, acceptable values and successfully sign my app. Thanks, guys!Kinnard
B
4

It may help someone.

Some days before I backed up my android project on gitlab and then installed windows 10. After that I cloned it. I knew the key alias and both the passwords exactly.

Then while generating signed apk I entered those credentials but failed.

I had placed the jks file in the app folder. I removed it from there and created separate folder in root folder of android project and placed jks file there.

Then I tried clean, rebuild project and then restarted android studio. Finally it built the signed apk :D

Breathy answered 25/2, 2019 at 18:22 Comment(0)
R
2

This issue occurs only when your Key Password Or Keystore Password Mis-matching.

Reeves answered 28/12, 2018 at 7:41 Comment(1)
That was not the case for meDanika
A
2

My passwords were same and still got this error. Clean, rebuild and restarting Android studio did not work for me. The only solution worked for me was moving the keystore.jks file to a new location. Hope this helps.

Agrigento answered 27/12, 2019 at 6:55 Comment(1)
I got the same passwords error, i simply re-wrote the passwords and it worked again. Hope this could help someoneCasting
D
1

I just removed the signingConfigs section from my app gradle file. Then rebuilt the project and it worked again.

Drona answered 26/2, 2020 at 6:58 Comment(0)
D
1

I simply removed the .iml file from my project. Then remodeled the project and it worked once more.

Dyaus answered 9/7, 2020 at 9:24 Comment(0)
D
1

For me the solution was a combination of 2 solutions here. I had to first do a gradle sync:

enter image description here

Then quit, clean and rebuild project.

enter image description here

My passwords never changed. And doing the clean and rebuild without first doing the gradle sync didn't work for me either. Android Studio version 4.1.2.

This was after having gone about a month without generating a previous version of the signed bundle and had never encountered this error before.

Danika answered 14/8, 2021 at 6:38 Comment(0)
G
1

I tried a clean and rebuild and gradle sync but kept getting the Cannot recover key error.

File > Invalidate Caches / Restart fixed the problem for me.

I did NOT need to change my key passwords or my .jks key file. I kept using my original "Key store password" and "Key password" (which are not identical).

Graehl answered 10/12, 2021 at 18:48 Comment(0)
L
0

I had a stroke of good fortune to check in Android Studio the Project Structure/Signing tab, and found the key password and store password listed in plain text. I thought they were the same as each other, but they weren't.

Lamellirostral answered 4/4, 2018 at 16:4 Comment(0)
T
0

If you have eclipse running, try to shut it down and generate a signed apk again.

In my case, I checked that all the passwords are correct and even generated a new key store from Android studio. It still did not work, but after I shut down eclipse that is running, everything just worked, with the old key store I used or with a newly generated one.

Triclinic answered 30/1, 2019 at 3:38 Comment(0)
W
0

I have zipped my signature file before when I first created it. When I got this error, I used it again. You can use it if you have a backup. I think we've broken things before they notice.

Weeks answered 21/2, 2019 at 18:34 Comment(0)
S
0

In my case i am using android studio 4.2.2, I changed the .jks file location and put it into desktop and then again tried to generate the key and it worked for me.

Scarificator answered 23/7, 2021 at 21:20 Comment(0)
R
0

If you're running gradlew from cmd/terminal on Windows, put " double quotes around your passwords/key/alias

gradlew <release> -Pandroid.injected.signing.store.file="....\something.jks" -Pandroid.injected.signing.store.password="password1" -Pandroid.injected.signing.key.alias="app" -Pandroid.injected.signing.key.password="password2"
Rosa answered 28/12, 2022 at 18:20 Comment(0)
B
0

Works in 2024:

Instead of trying to manipulate the jks file, do the following:

  1. Open the app page in the Google Play Console.
  2. In the Release section, find Setup->App signing.
  3. Find the button Request upload key reset.
  4. Then, recreate a new jks key for your app according to the instructions behind that button.
  5. !!!Important!!! Wait for 2 days before you can update the app.

Of course, I tried everything above because it's faster than waiting for two days.

P.S. I don't know why, but maybe the key was corrupted for unknown reasons.

Bagasse answered 27/3 at 17:10 Comment(0)
R
0

This problem happened to me too, the only thing I did was to copy the key file to another place and the problem was solved

Roundhouse answered 29/3 at 10:52 Comment(0)
H
-1

I was facing the same problem. In my case, After sync project with gradle files resolved this issue. This might help someone.

Histidine answered 12/12, 2019 at 8:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.