Unable to export signed APK in Android Studio
Asked Answered
E

3

5

When I use keytool -list -keystore /path/to/keyfile.jks and give my password, I'm able to see the entry there, but when I use the same password while trying to Generate signed APK using the same password, I get the error

Cannot load key store: Keystore was tampered with, or password was incorrect

Please help!

Endamoeba answered 27/7, 2014 at 5:22 Comment(7)
Try to import your project into eclipse, and then go to file export, and provide the proper information when prompted. Android Studios is still in its beta and therefore you should expect bugs.Alp
@Alp Thanks for the response. Just a clarification required. Changing the location of keystore shouldn't count as tampering, right? The thing is, I upgraded Android Studio, and took a backup of the older installation directory. The keystore file was placed in older directory. An idea aboutthat?Endamoeba
It should be fine as long as you update or point the directory for the keystore if it asks and cannot find it.Alp
@Alp I did find an answer after all. Check out my response below. :) And by the way, the app that I launched is play.google.com/store/apps/details?id=thoughtsdiary.free Check it out of you wish to.Endamoeba
that is actually a beautifully made app and I love the idea; unique. Going to download and use. Great work!Alp
I really did like your app, I have a couple cool suggestions. Email me if your interested. My contact email is provided in my stackoverflow account details.Alp
Just encountered the same problem but, with just a clean project - invalidates cache and restart, everything worked again.Joshuajoshuah
E
18

Got the answer after 20 hours of tireless searching. Apparently there is some issue with the character '&' in passwords as mentioned here https://code.google.com/p/android/issues/detail?id=36350 Although in my case, the character was '@'.

For anyone who gets stuck, here is what I did (and what should work for them too)

  1. I used the keytool -keypasswd -alias <key_name> -keystore mykeystorek.jks command to change password for my key alias password.
  2. Since I suspected my original file had some issues, I thought it best to export the keys to another file. I did that using keytool -importkeystore -srckeystore my.keystore.jks -destkeystore new.keystore -deststoretype pkcs12 followed by keytool -importkeystore -srckeystore new.keystore -srcstoretype pkcs12 -destkeystore final.keystore -deststoretype jks.

What this does is, export the original keystore values in PKCS12 format, and then back to Java Keystore format in the filename final.keystore. In all these commands, the prompt asked for new destination password, which I carefully chose, avoiding @ and &.

And it works now! As indicated in the link shared above,this seems to be due to some update pushed in SDK Tools 20. I know it's bad. The other app owners seem pretty pissed at Google too. :(

Endamoeba answered 29/7, 2014 at 16:22 Comment(9)
+1 for resolving the problem and coming back to provide the community with the answer. Glad you resolved it :)Alp
I am running into the same EXACT problem, keystore passwords created with "@" in them, on an older version of Android Studio. Have since upgraded to much newer build, and no matter what I do (following your directions above), I get Keystore was tampered with or password was incorrect. Do i need to use an older version of keytool?Modena
@Modena Sorry for coming in late on this; guess you've already resolved this. But apparently, these characters were a no-no while signing using Android Studio. Although I haven't tried this after Android Studio came out of Beta recently. Let us know if you were able to. :)Endamoeba
its asking :- Enter source keystore password:Forefront
Someone give this person a medal.Bootleg
Since I'm trying to execute the first command, unfortunately, I'm getting this error in the terminal window: The system cannot find the file specified.Pard
@SankalpSharma On executing the first command I am getting the following error The system cannot find the file specified. @yahme3 Were you able to solve this issue?Undertint
@KavinRajuS You will have to replace my file names with your actual ones.Endamoeba
I faced the same problem then i used alpha numeric password without including special characters and it worked. Thanks.Machinery
R
0

I could not get Android Studio to sign my APK no matter what I tried.

I was getting this error even when I attempted to create a new keystore and key and used that to sign it during Android Studio build release.

In the end, I got it to work by using Keystore explorer to re-set the password to 'changeit' for both the keystore as well as the signing key that I was using.

This is both disconcerting and confusing to me. There is no way that this should happen, but it does.

Rebel answered 30/8, 2015 at 19:48 Comment(1)
Agreed that it is way too confusing and almost irreversible, and impacts the developer a lot. I think we should try documenting it in a much clearer way. I'll hopefully start a public github repo for documenting common pitfalls encountered by developers in this.Endamoeba
T
-1

I had a similar issue which stemmed from a corrupt my-upload-key file. To solve problem, I deleted it from the app and android directories, created it again following this link https://reactnative.dev/docs/signed-apk-android. running the gradlew buildRelease command was a success.

Tahoe answered 7/12, 2020 at 6:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.