Gradle 任务 assembleRelease 失败,退出码 1:任务 ':app:signReleaseBundle' 执行失败 > 创建密钥时出错:密钥库格式无效
Gradle task assembleRelease failed with exit code 1: Execution failed for task ':app:signReleaseBundle' > Key was created with errors: Key was created with errors: Invalid keystore format
ID: flutter/signing-key-creation-error
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Flutter 3.16+ | active | — | — | — |
| Gradle 8.3+ | active | — | — | — |
| Android Studio Iguana 2023.2.1+ | active | — | — | — |
根因分析
用于签署发布包的密钥库文件已损坏、格式不受支持,或使用与当前构建环境不同的 Java 版本创建。
English
The keystore file used for signing the release bundle is corrupted, in an unsupported format, or was created with a different Java version than the current build environment.
官方文档
https://developer.android.com/studio/publish/app-signing解决方案
-
使用 Java 11 或更高版本重新生成密钥库:keytool -genkey -v -keystore release.keystore -alias my-key -keyalg RSA -keysize 2048 -validity 10000 -storetype JKS。然后更新 android/key.properties 中的文件路径。
-
将现有密钥库转换为 PKCS12 格式:keytool -importkeystore -srckeystore old.keystore -destkeystore new.keystore -deststoretype pkcs12。然后在 key.properties 中引用新文件。
-
如果使用 Android Studio,通过 Build > Generate Signed Bundle/APK > Create new 创建新密钥库。确保 File > Project Structure > SDK Location 中的 Java 版本与密钥库创建版本匹配。
无效尝试
常见但无效的做法:
-
70% 失败
Converting the keystore to PKCS12 format using keytool without specifying the correct alias often results in missing key entries and signature failures.
-
90% 失败
Deleting the keystore and creating a new one without backing up the original causes loss of the signing key, preventing app updates on the same package name.
-
80% 失败
Copying the keystore from another project without changing the key alias may cause signature conflicts with Google Play Store.