Signing a release build stops with Failed to read key from keystore
Failed to read key from keystoreShort 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.
Fix it fast
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.jks2Match what you see, then jump to its fix
- 1
The 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
The 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
keytool -list works only when you pass -storetypeThe keystore is JKS but Java tries another typeFix
- 1
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 assembleReleaseConfirmed by developer.android.com
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.jks2Fix
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 bundleReleaseConfirmed by docs.oracle.com
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 PKCS122Fix
Note which type opens the file and keep using that file with its own type.
keytool -list -keystore my-release-key.jks -storetype JKS3Verify
List the new file and rebuild with it.
keytool -list -keystore my-release-key.p12 -storetype PKCS12Confirmed by docs.oracle.com
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
adb cannot start because something already holds its port
adb start-server failed
The adb server must bind local TCP port 5037, and every adb client talks to it there.
2 causes, each with a fixMobile apps
The phone shows as unauthorized and Android Studio will not run the app
adb devices lists the phone but Android Studio cannot deploy to it
An unauthorized phone means it has not trusted this computer's RSA key.
3 causes, each with a fixMobile 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 fixMobile apps
adb cannot connect to its daemon or start the server
* daemon started successfully *
The adb server is a background process on your computer that listens on TCP port 5037.
2 causes, each with a fixMobile apps
adb prints 'server version doesn't match this client; killing...'
adb server version doesn't match this client; killing...
adb runs a background server, and every adb command is a client.
3 causes, each with a fixMobile 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