# Gradle 任务 assembleRelease 失败，退出码 1：任务 ':app:signReleaseBundle' 执行失败 > 创建密钥时出错：密钥库格式无效

- **ID:** `flutter/signing-key-creation-error`
- **领域:** flutter
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

用于签署发布包的密钥库文件已损坏、格式不受支持，或使用与当前构建环境不同的 Java 版本创建。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Flutter 3.16+ | active | — | — |
| Gradle 8.3+ | active | — | — |
| Android Studio Iguana 2023.2.1+ | active | — | — |

## 解决方案

1. ```
   使用 Java 11 或更高版本重新生成密钥库：keytool -genkey -v -keystore release.keystore -alias my-key -keyalg RSA -keysize 2048 -validity 10000 -storetype JKS。然后更新 android/key.properties 中的文件路径。
   ```
2. ```
   将现有密钥库转换为 PKCS12 格式：keytool -importkeystore -srckeystore old.keystore -destkeystore new.keystore -deststoretype pkcs12。然后在 key.properties 中引用新文件。
   ```
3. ```
   如果使用 Android Studio，通过 Build > Generate Signed Bundle/APK > Create new 创建新密钥库。确保 File > Project Structure > SDK Location 中的 Java 版本与密钥库创建版本匹配。
   ```

## 无效尝试

- **** — Converting the keystore to PKCS12 format using keytool without specifying the correct alias often results in missing key entries and signature failures. (70% 失败率)
- **** — 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. (90% 失败率)
- **** — Copying the keystore from another project without changing the key alias may cause signature conflicts with Google Play Store. (80% 失败率)
