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

问题描述

一周以来,我一直在尝试从 Flutter 应用程序创建 android 应用程序包,并且我从 Create an upload keystore 的官方 Flutter 网站上关注了

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

keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload

提示我输入密钥库密码,我已经写了 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]

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

storePassword=android
keyPassword=android
keyAlias=upload
storeFile=/Users/faizfareed/upload-keystore.jks

最后我配置了 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 {
         ...
   }

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
       }
   }

使用签名配置信息:

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

最后当我执行 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

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

enter image description here

我也试过关注solution,但对我没有任何作用

谁能帮我解决这个错误无效的密钥库格式

解决方法

我只是有同样的错误。 我从 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

我推荐使用命令

flutter doctor -v

检查Java路径'Java二进制文件:' enter image description here

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...