Reputation: 4555
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!
Upvotes: 129
Views: 109277
Reputation: 372
My situation was like this: my Android project was in old Android studio 3.1.3 . I used a jks file. I upgraded to Android Studio 2021 . Moved the project to AS 2021 also. And the same jks file. But I got error that jks file could not be read. The solution for me was to open the jks file in the application "Keystore Explorer" and just save it in another file. After "Generate signed Apk" (in AS 2021) it produced the same certificate fingerprint. I needed that because my application integrates a bank project, so it was needed a specific fingerprint.
Upvotes: 0
Reputation: 1637
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
Upvotes: 1
Reputation: 2071
Works in 2024:
Instead of trying to manipulate the jks
file, do the following:
jks
key for your app according to the instructions behind that button.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.
Upvotes: 2
Reputation: 367
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"
Upvotes: 0
Reputation: 1317
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).
Upvotes: 1
Reputation: 5575
For me the solution was a combination of 2 solutions here. I had to first do a gradle sync:
Then quit, clean and rebuild project.
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.
Upvotes: 1
Reputation: 191
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.
Upvotes: 0
Reputation: 2601
I simply removed the .iml
file from my project. Then remodeled the project and it worked once more.
Upvotes: 1
Reputation: 367
I just removed the signingConfigs section from my app gradle file. Then rebuilt the project and it worked again.
Upvotes: 1
Reputation: 910
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.
Upvotes: 2
Reputation: 357
I was facing the same problem. In my case, After sync project with gradle files resolved this issue. This might help someone.
Upvotes: -1
Reputation: 506
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
Upvotes: 21
Reputation: 1123
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
Upvotes: 4
Reputation: 850
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.
Upvotes: 0
Reputation: 401
[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.
Upvotes: 13
Reputation: 728
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.
Upvotes: 0
Reputation: 646
This issue occurs only when your Key Password Or Keystore Password Mis-matching.
Upvotes: 3
Reputation: 1946
[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:
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.
Upvotes: 75
Reputation: 1985
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.
Upvotes: 0
Reputation: 2325
If it can help anyone - the problem in my case was that the "Key store password" and "Key password" were incorrect.
Upvotes: 37
Reputation: 4555
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.
Upvotes: 140