102

I'm developing android app under intellij and gradle. and using following way to generate keystore file:

keytool -genkey -v -keystore my-release-key.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 10000

then used the keystore file in build.gradle:

signingConfigs {
    robert {
        storePassword 'robert'
        storeFile file('/Users/bournewang/Documents/Project/android.keystore')
        keyPassword 'robert'
        keyAlias 'mike'
    }
}

when finally trying to generate signed apk file: ./gradlew assembleRelease

it gives the error:

Execution failed for task ':Myexample:packageRelease'.

Failed to read key from keystore

LiangWang
  • 8,038
  • 8
  • 41
  • 54

16 Answers16

91

In order to find out what's wrong you can use gradle's signingReport command.

On mac:

./gradlew signingReport

On Windows:

gradlew signingReport
Amt87
  • 5,493
  • 4
  • 32
  • 52
Tom Susel
  • 3,397
  • 1
  • 24
  • 25
  • +1 thank you for that hint! This way I figured out, that when running signingReport it did list my release signing config, but only the Store location, the variant, the config and the alias. It was missing Sha1, md5 and the valid until. The reason was: my alias was wrong : ) - so if above command lists the entire set of info, you should be all set (variant, config, store, alias, md5, sha1, valid until), if not, make sure you have passwords, keystore and alias set up correctly in your project's build.gradle file – AgentKnopf Jan 20 '15 at 09:22
  • 1
    Running this it is showing that: `Variant: release Config: none` Is my .keystore deleted? – Shajeel Afzal May 26 '15 at 20:23
  • thanks a bunch! gradlew is located directly in ones android studio project directory. Calling signingReport reveals that the debug-key's alias is actually "AndroidDebugKey"... – hotzen Jun 04 '15 at 20:24
  • Or for me it was (in the android platform director) ./gradlew.bat signingReport – csga5000 May 11 '16 at 22:20
  • I had the wrong alias and got a result with no errors but not the desired data, so for those who at first didn't know how o interpret the report, your key MUST be print with SHA1 and MD5 values next to it to consider it correct. – Felipe Sabino Jun 29 '16 at 11:54
  • This saved me a lot – Idris Stack May 07 '20 at 08:37
  • Guys i've got this error and i don't know how to solved it. Error: Failed to read key android-production from store "/Users/rodrigodiasdefigueiredo/Desktop/z-mobile/android/app/android-production.keystore": Get Key failed: Given final block not properly padded. Such issues can arise if a bad key is used during decryption. – Rodrigo Dias Aug 02 '23 at 10:00
75

Check your keystore file for first, in you example you creating file with name my-release-key.keystore. If its correct and really present in folder Users/bournewang/Documents/Project check alias, in your example it is -alias alias_name, but in config you specified alias mike

cooperok
  • 4,249
  • 3
  • 30
  • 48
9

Most likely that your key alias does not exist for your keystore file.

This answer should fix your signing issue ;)

Community
  • 1
  • 1
Stephen Vinouze
  • 1,815
  • 1
  • 17
  • 28
6

Removing double-quotes solve my problem, now its:

DEBUG_STORE_PASSWORD=androiddebug
DEBUG_KEY_ALIAS=androiddebug
DEBUG_KEY_PASSWORD=androiddebug
Aniruddh Parihar
  • 3,072
  • 3
  • 21
  • 39
fincode
  • 104
  • 1
  • 3
4

In my case, while copying the text from other source it somehow included the space at the end of clipboard entry. That way the key password had a space at the end.

Stjepan Golemac
  • 121
  • 2
  • 4
3

For me this worked.

  1. Go to <your_app_name>/android.
  2. On the terminal use ./gradlew signingReport for Mac OS and gradlew signingReport for Windows.
  3. Check if each element of each task has a Variant, Config, Store, Alias, MD5, SHA1, SHA-256, Valid until. If so you should be good.
  4. If any of the above are absent then try to regenerate the key store by following the instructions on this page.
  5. Copy the key store file and paste it inside <your_app_name>/android/app.

Some things that I was doing wrong while generating the key store file were.

  1. Using quotations on MYAPP_UPLOAD_..._PASSWORD's.
MYAPP_UPLOAD_STORE_PASSWORD="Password123"
MYAPP_UPLOAD_KEY_PASSWORD="Password123"
  1. I used \J4ct@RD as a password and it did not work. I later changed the password to something that was just aplphanumeric and it worked.
2

In Android Studio go to Build > Clean Project then re-generate signed APK using Build > Generate Signed Bundle / APK... and then clear password-fields and re-enter your passwords

MTM
  • 113
  • 1
  • 8
  • For those who typed alias wrong in the first time, and keeps getting the same error even if they changed the alias can try this. It worked for me. – Egemen Hamutçu Dec 22 '21 at 12:21
2

In my case it happened in Debug build variant. So I closed the android studio. deleted the debug.keystore and debug.keystore.lock files and open the project again. That fixed my problem.

Ehsan Shadi
  • 609
  • 6
  • 17
1

For someone not using the signing configs and trying to test out the Cordova Release command by typing all the parameters at command line, you may need to enclose your passwords with single quotes if you have special characters in your password

cordova run android --release -- --keystore=../my-release-key.keystore --storePassword='password' --alias=alias_name --password='password'
Mohamed Azher
  • 411
  • 5
  • 3
1

The big thing is either the alias or the other password is wrong. Kindly check your passwords and your issue is solved. Incase you have forgotten password, you can recover it from the androidStuido3.0/System/Log ... Search for the keyword password and their you are saved

Daniel Nyamasyo
  • 2,152
  • 1
  • 24
  • 23
  • Could you kindly confirm if the Log file i should be looking at is this == idea.log , at the path == C:\Users\xxxx\.AndroidStudio3.5\system\log\idea.log – Rohit Dhankar Jan 11 '20 at 09:09
1

Make sure you have correct the folliwn

  • keystore file path
  • keystore alies name
  • keystore password

keystore in android/key.properties

enter image description here

1

in my case for some reason, after updating android studio to the last stable version, the password that was always by default got changed, i just had to set correct password again and it worked

karique
  • 533
  • 6
  • 17
1

Depending on where you generated the keyfile, keytool might refer to a different binary, running on a different JVM version. These are not necessarily compatible, try adjusting the versions.

phil294
  • 10,038
  • 8
  • 65
  • 98
0

It could be any one of the parameter, not just the file name or alias - for me it was the Key Password.

A-S
  • 2,547
  • 2
  • 27
  • 37
0

I got same error today.

Execution failed for task ':app:packageRelease'. A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable com.android.ide.common.signing.KeytoolException: Failed to read key news from store "E:\keystore\news.jks": Keystore was tampered with, or password was incorrect

I had same key password and key store password. But i wrote a wrong password.

Rohaitas Tanoli
  • 624
  • 4
  • 16
0

for me was need to update the key when I transfer the source code to another PC

the steps using UI

files ==> Project Structure... ==> Modules ==>Sining Configs

enter image description here

Hassan Badawi
  • 302
  • 1
  • 10