Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Signing a release build stops with Failed to read key from keystore

ErrorFailed to read key from keystore

Short answer

Gradle opened the signing config but could not get the key out of the keystore. Three things cause it: storeFile points at the wrong place, the alias or password does not match what is inside the file, or the keystore type is not what Java expects. Run keytool -list on the file first; it shows what is really inside.

  • Applies to Android Gradle Plugin 8.x, Gradle 8 and 9, JDK 17 and 21
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    List what the keystore really contains, using the same file and store password your build uses. If this command fails, the problem is the file or the password, not Gradle.

    keytool -list -keystore /absolute/path/to/my-release-key.jks
  2. 2Match what you see, then jump to its fix

    1. 1The path in the error message is not where your keystore lives, or keytool says the file does not existstoreFile points at a different file than you thinkFix
    2. 2The alias in the error does not appear in the keytool list, or keytool asks for a password you do not haveThe alias or a password is wrongFix
    3. 3keytool -list works only when you pass -storetypeThe keystore is JKS but Java tries another typeFix

What does the error look like?

  • Failed to read key from keystore

Cause 1 of 3

storeFile points at a different file than you think

1Check

Print the path Gradle resolves. Android's build docs say storeFile needs either an absolute path or a keystore file in the same directory as the build.gradle file, so a relative path is read from the module folder, not the project root.

ls -l app/my-release-key.jks
grep -n "storeFile" app/build.gradle*

2Fix

Use an absolute path, or put the keystore next to the module's build file and name it there.

// app/build.gradle.kts
signingConfigs {
    create("release") {
        storeFile = file("my-release-key.jks")
        storePassword = System.getenv("KS_PASS")
        keyAlias = "my-alias"
        keyPassword = System.getenv("KEY_PASS")
    }
}

3Verify

Build the release variant again.

./gradlew assembleRelease

Confirmed by developer.android.com

Did this fix it?

Cause 2 of 3

The alias or a password is wrong

1Check

keytool -list without -alias prints every entry, so you can read the real alias. A keystore has a store password and each key can have its own key password; the build needs both right.

keytool -list -v -keystore my-release-key.jks

2Fix

Copy the alias exactly as keytool prints it (case matters) and use the store password for storePassword and the key's password for keyPassword.

keyAlias = "my-alias"          // exact alias from keytool -list
storePassword = System.getenv("KS_PASS")
keyPassword = System.getenv("KEY_PASS")

3Verify

Check one alias on its own, then rebuild.

keytool -list -keystore my-release-key.jks -alias my-alias
./gradlew bundleRelease

Confirmed by docs.oracle.com

Did this fix it?

Cause 3 of 3

The keystore is JKS but Java tries another type

1Check

PKCS12 is the default keystore type since JDK 9, and JKS is a separate format. A file in the other format can fail with the default settings.

keytool -list -keystore my-release-key.jks -storetype JKS
keytool -list -keystore my-release-key.jks -storetype PKCS12

2Fix

Note which type opens the file and keep using that file with its own type.

keytool -list -keystore my-release-key.jks -storetype JKS

3Verify

List the new file and rebuild with it.

keytool -list -keystore my-release-key.p12 -storetype PKCS12

Confirmed by docs.oracle.com

Did this fix it?

How do I stop it coming back?

  • Keep store and key passwords in environment variables or a local properties file outside git, not in build.gradle.
  • Write the alias and the keystore type next to the backup of the keystore, so a later build does not guess.
  • Run keytool -list on the keystore whenever you move or copy it to a CI machine.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Mobile apps

Android Studio cannot pair the phone over Wi-Fi

The Pair devices over Wi-Fi dialog lists no device

Wireless pairing needs the phone on Android 11 or higher and on the same Wi-Fi network as the computer, with current Platform-Tools.

4 causes, each with a fix

Mobile apps

adb tcpip 5555 fails because no device is found

adb: more than one device/emulator

adb tcpip only works while the device is attached and listed by adb, because it tells the phone to start listening on port 5555.

4 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.