106

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!

wasimsandhu
  • 4,303
  • 8
  • 23
  • 35
  • 2
    If you've used character & or @ in your keystore password, then don't scroll down to the answer section, jump to this [link](https://stackoverflow.com/questions/24978166/unable-to-export-signed-apk-in-android-studio), for sharma's answer. – meyasir Oct 04 '18 at 16:49

14 Answers14

125

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.

wasimsandhu
  • 4,303
  • 8
  • 23
  • 35
  • 5
    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. – Alen Siljak Sep 11 '15 at 21:41
  • Same with me. The issue started from one day to another! I did'nt use old backup files... It just happend. – Tino Sep 17 '15 at 20:55
  • 7
    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? – Tushar Gogna Feb 02 '16 at 05:00
  • Any news? This isn't working for me, still getting cannot recover key error – DaxHR Apr 06 '16 at 13:00
  • I just signed an apk with different passwords? – whyoz Jun 01 '16 at 21:08
  • 1
    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! – Neo Aug 08 '16 at 10:27
  • 5
    Its giving this error still now in my case: "keytool error: java.security.UnrecoverableKeyException: Cannot recover key" – 0xAliHn Nov 20 '16 at 06:04
  • 2
    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" – Ammar Bukhari Dec 11 '16 at 05:45
  • I have been facing same issue. – Ronak Gadhia Aug 10 '17 at 07:42
  • 1
    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. – Kavin Raju S Dec 24 '18 at 02:11
  • @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 first – BlackHoleGalaxy Apr 23 '19 at 10:50
  • Not working. Following error showing keytool error: java.security.UnrecoverableKeyException: Cannot recover key – mohit Jun 17 '19 at 10:24
  • 2
    Interesting how it's explicitly mentioned in [Android documentation](https://developer.android.com/studio/publish/app-signing#generate-key) that these two passwords should be different – Ehsan Khaveh Jun 18 '20 at 11:57
  • 1
    Have same issue here. Anyone has a solution? – ikhsanudinhakim Jul 18 '20 at 01:48
  • I faced the same problem then i used alpha numeric password without including special characters and it worked. Thanks. – Kamlesh Aug 15 '20 at 07:10
  • 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. – Acmpo6ou Apr 03 '21 at 13:31
70

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

Build3r
  • 1,188
  • 9
  • 18
  • 3
    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. – George Jul 12 '17 at 18:08
  • Thanks! I was using the `master password` that I entered when signing the apk, but I just needed to repeat the `key password`. – JCarlosR Aug 24 '17 at 13:44
  • I had never seen a log file. To check log files provides me a very strong clue. Thank you. – hata Sep 07 '17 at 14:06
  • OMG LOVE YOU MAN; you saved my life, Lol, for me was because i just updated Android Studio so my password was losted – Andres Felipe Oct 29 '17 at 01:30
  • 8
    Does this work for AndroidStudio3.0? I am seeing my passwords as *********. – TheLearner Nov 09 '17 at 20:51
  • 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. – Phan Dinh Thai Aug 25 '18 at 07:52
  • 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. – Yar Jan 18 '19 at 09:54
  • 1
    My file says: -Pandroid.injected.signing.store.password=*********, -Pandroid.injected.signing.key.alias=mykey, -Pandroid.injected.signing.key.password=********* – Androidcoder Feb 06 '19 at 13:29
  • 2
    @Androidcoder Android studio team fixed this loophole in the recent versions. – Build3r Feb 19 '19 at 12:45
  • Just to be sure, does that mean that you were incorrect and that both passwords weren't the same? – Wouter Vandenputte Sep 14 '20 at 10:04
  • @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. – Build3r Sep 17 '20 at 14:29
31

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

MorZa
  • 1,695
  • 14
  • 29
19

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

Zeeshan Tufail
  • 416
  • 3
  • 8
10

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

LiebrandApps
  • 271
  • 3
  • 5
  • 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. – Alejandro Cumpa Apr 15 '19 at 16:22
  • 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! – Peter Gluck May 30 '20 at 00:38
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

Makarand
  • 623
  • 4
  • 16
2

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

Arjun G
  • 524
  • 1
  • 6
  • 17
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.

Andrain
  • 659
  • 1
  • 13
  • 36
1

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

Martin B
  • 267
  • 4
  • 7
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.

saswanb
  • 1,855
  • 1
  • 14
  • 21
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.

Nick
  • 118,076
  • 20
  • 42
  • 73
RedSIght
  • 137
  • 1
  • 9
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.

Mahmut K.
  • 316
  • 3
  • 11
0

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

Vikas Rai
  • 139
  • 1
  • 8
0

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

Muhammad Waleed
  • 2,407
  • 2
  • 23
  • 68