Android Studio: cannot recover key

AndroidAndroid Keystore

Android Problem Overview


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!

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

[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.

Solution 3 - Android

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

Solution 4 - Android

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

Solution 5 - Android

[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.

Solution 6 - Android

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

Solution 7 - Android

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

Solution 8 - Android

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.

Solution 9 - Android

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.

Solution 10 - Android

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

Solution 11 - Android

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

Solution 12 - Android

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.

Solution 13 - Android

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.

Solution 14 - Android

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.

Solution 15 - Android

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

Solution 16 - Android

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.

Solution 17 - Android

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).

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionwasimsandhuView Question on Stackoverflow
Solution 1 - AndroidwasimsandhuView Answer on Stackoverflow
Solution 2 - AndroidBuild3rView Answer on Stackoverflow
Solution 3 - AndroidMorZaView Answer on Stackoverflow
Solution 4 - AndroidZeeshan TufailView Answer on Stackoverflow
Solution 5 - AndroidLiebrandAppsView Answer on Stackoverflow
Solution 6 - AndroidMakarandView Answer on Stackoverflow
Solution 7 - AndroidArjun GView Answer on Stackoverflow
Solution 8 - AndroidAndrainView Answer on Stackoverflow
Solution 9 - AndroidLoren.AView Answer on Stackoverflow
Solution 10 - AndroidMartin BView Answer on Stackoverflow
Solution 11 - AndroidMuhammad WaleedView Answer on Stackoverflow
Solution 12 - AndroidsaswanbView Answer on Stackoverflow
Solution 13 - AndroidRedSIghtView Answer on Stackoverflow
Solution 14 - AndroidMahmut K.View Answer on Stackoverflow
Solution 15 - AndroidVikas RaiView Answer on Stackoverflow
Solution 16 - AndroidSourav RanaView Answer on Stackoverflow
Solution 17 - AndroidLifesView Answer on Stackoverflow