Mac OS Flutter 构建 appbundle 失败:密钥库格式无效

Fai*_*eed 1 android apk build.gradle flutter flutter-macos-2.0.0-stable

一周以来,我一直在尝试从 flutter 应用程序创建 android 应用程序包,并且我遵循根据官方 flutter 网站创建上传密钥库

在 Mac OS 中,我尝试在终端中执行以下命令

keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload
Run Code Online (Sandbox Code Playgroud)

它提示我输入密钥库密码,android然后重新输入新密码:android 在我填写的一系列问题和答案之后,就像你的名字和姓氏一样?,你的组织单位的名称是什么?,你的组织的名字是什么?,你的城市或地区的名字是什么?,你的州或省的名字是什么?,这个单位的两个字母的国家代码是什么?,最后问了信息是正确的,我回答是,它在提示这样的同时制作了 .jks 文件

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
    for: CN=Unknown, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown
[Storing /Users/faizfareed/upload-keystore.jks]
Run Code Online (Sandbox Code Playgroud)

之后我创建了一个名为的文件[project]/android/key.properties,其中包含对密钥库的引用,文件中包含以下信息

storePassword=android
keyPassword=android
keyAlias=upload
storeFile=/Users/faizfareed/upload-keystore.jks
Run Code Online (Sandbox Code Playgroud)

最后我配置了gradle[project]/android/app/build.gradle文件。

android块之前添加了来自属性文件的密钥库信息:

   def keystoreProperties = new Properties()
   def keystorePropertiesFile = rootProject.file('key.properties')
   if (keystorePropertiesFile.exists()) {
       keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
   }

   android {
         ...
   }
Run Code Online (Sandbox Code Playgroud)

key.properties文件加载到keystoreProperties对象中。

替换buildTypes块:

buildTypes {
       release {
           // TODO: Add your own signing config for the release build.
           // Signing with the debug keys for now,
           // so `flutter run --release` works.
           signingConfig signingConfigs.debug
       }
   }
Run Code Online (Sandbox Code Playgroud)

使用签名配置信息:

signingConfigs {
       release {
           keyAlias keystoreProperties['keyAlias']
           keyPassword keystoreProperties['keyPassword']
           storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
           storePassword keystoreProperties['storePassword']
       }
   }
   buildTypes {
       release {
           signingConfig signingConfigs.release
       }
   }
Run Code Online (Sandbox Code Playgroud)

最后当我执行flutter build appbundle命令时,它给出了这样的错误

faizfareed@Faizs-MBP building_apk % flutter build appbundle 

Building without sound null safety
For more information see https://dart.dev/null-safety/unsound-null-safety

                                                                        
FAILURE: Build failed with an exception.                                
                                                                        
* What went wrong:                                                      
Execution failed for task ':app:signReleaseBundle'.                     
> A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade
   > Failed to read key upload from store "/Users/faizfareed/upload-keystore.jks": Invalid keystore format
                                                                        
* Try:                                                                  
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
                                                                        
* Get more help at https://help.gradle.org                              
                                                                        
BUILD FAILED in 7s                                                      
Running Gradle task 'bundleRelease'...                                  
Running Gradle task 'bundleRelease'... Done                         7.8s
Gradle task bundleRelease failed with exit code 1
Run Code Online (Sandbox Code Playgroud)

作为参考,我还附上了终端的图像

在此处输入图片说明

我也尝试过以下解决方案,但对我没有任何作用

谁能帮我解决这个错误Invalid keystore formate

小智 5

我只是有同样的错误。我已经从https://docs.oracle.com/en/java/javase/15/install/installation-jdk-macos.html#GUID-2FE451B0-9572-4E38-A1A5-568B77B146DE安装了 JDK 但没有必要因为Android Studio有它,所以我卸载了它。

我在终端中使用了下一个命令

/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Run Code Online (Sandbox Code Playgroud)

我建议使用命令

flutter doctor -v
Run Code Online (Sandbox Code Playgroud)

检查Java路径'Java二进制文件:' 在此处输入图片说明