简体   繁体   English

构建 AAB 时出错 - Flutter (Android) - 完整性检查失败:java.security.NoSuchAlgorithmException:算法 HmacPBESHA256 不可用

[英]Error building AAB - Flutter (Android) - Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available

I am trying to build an AAB for my flutter app.我正在尝试为我的 flutter 应用构建 AAB。 I generated the keystore using the following below command:我使用以下命令生成了密钥库:

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

I have a key.properties file, and I have referenced it using the provided code in the flutter docs.我有一个key.properties文件,我已经使用 flutter 文档中提供的代码引用了它。 How can I solve this Java related issue?我该如何解决这个 Java 相关问题? My program throws the following 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 pckey from store "/Users/jrperfetto/pc-keystore.jks": Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available
                                                   

I was getting the same error, I try this command我遇到了同样的错误,我试试这个命令

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

with extra attribute带有额外属性

-storetype JKS

it helps me to solve my problem and successfully create bundle.它可以帮助我解决我的问题并成功创建捆绑包。

The -storetype JKS tag is only required for Java 9 or newer.只有 Java 9 或更高版本需要 -storetype JKS 标签。 As of the Java 9 release, the keystore type defaults to PKS12.从 Java 9 版本开始,密钥库类型默认为 PKS12。

It turns out i was generating my signing key using a different Java Version than my app was using to build the app.事实证明,我使用不同于我的应用程序用于构建应用程序的 Java 版本生成我的签名密钥。 You can check this by running flutter doctor -v and seeing where the Java binary is located, and comparing it to when you run "which java".您可以通过运行 flutter doctor -v 并查看 Java 二进制文件的位置来检查这一点,并将其与运行“which java”时进行比较。

The solution is to run your keygen command prefixed with the location of the Java bin found in the flutter doctor output like so:解决方案是运行以 flutter 医生 output 中的 Java bin 的位置为前缀的 keygen 命令,如下所示:

/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/keytool -genkey -v -keystore ~/pc-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias pckey

If you haven't already created a keystore file:如果您尚未创建密钥库文件:

  1. Mac:苹果电脑:
keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS
  1. Windows (change USER_NAME): Windows(更改 USER_NAME):
keytool -genkey -v -keystore "c:\Users\USER_NAME\upload-keystore.jks" -storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias upload

If you have already created a keystore file before:如果您之前已经创建了密钥库文件:

keytool -importkeystore -srckeystore "path/to/upload-keystore.jks" -destkeystore "path/to/new-upload-keystore.jks" -deststoretype JKS

in android folder in app folder open build.gradle and make sure to keep在应用程序文件夹中的 android 文件夹中打开 build.gradle 并确保保留

(buildTypes { release { signingConfig signingConfigs.debug } }) (buildTypes { release { signingConfig signingConfigs.debug } })

and before prepare app bundle change it to (signingConfig signingConfigs.release)并在准备应用程序包之前将其更改为 (signingConfig signingConfigs.release)

It solves me when I remove debug.keystore from the bellow directory.当我从波纹管目录中删除 debug.keystore 时,它解决了我的问题。

/Users/tariqul/.android/debug.keystore /Users/tariqul/.android/debug.keystore

I don't know if the way I solved the problem is the right way, and I don't know if others will solve it this way, but I think I would have solved it if I had done a lot of things.我不知道我解决问题的方法是不是对的,也不知道别人会不会这样解决,但我想如果我做了很多事情,我会解决的。

I adapted JAVA_HOME to the form of the java binary that came up with flutter doctor -v like this我将 JAVA_HOME 改编为 java 二进制文件的形式,该二进制文件与flutter doctor -v类似

% flutter doctor -v                            
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
.
.
.
    • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java

and set JAVA_HOME to .zshrc并将JAVA_HOME.zshrc

% cd ~
% vi .zshrc

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
% echo $JAVA_HOME
/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home

and

% flutter clean
% flutter build appbundle

and that works那行得通

% flutter build appbundle

💪 Building with sound null safety 💪

Running Gradle task 'bundleRelease'...                                  
Running Gradle task 'bundleRelease'... Done                         4.1s
✓ Built build/app/outputs/bundle/release/app-release.aab (21.2MB).

I got the same issue yesterday.我昨天遇到了同样的问题。 I deleted my old debug key, which is located at /Users/<username>/.android/debug.keystore .我删除了位于/Users/<username>/.android/debug.keystore的旧调试密钥。 I think this is the simplest way to handle this problem for a Newbie like me.我认为对于像我这样的新手来说,这是处理这个问题的最简单方法。

PS Not sure about the "release" mode. PS不确定“发布”模式。 This just works for "debug" mode.这仅适用于“调试”模式。

Note: The keytool command might not be in your path—it's part of Java, which is installed as part of Android Studio.注意:keytool 命令可能不在您的路径中 - 它是 Java 的一部分,它作为 Android Studio 的一部分安装。 For the concrete path, run flutter doctor -v and locate the path printed after 'Java binary at:'.对于具体路径,运行 flutter doctor -v 并找到打印在“Java binary at:”之后的路径。 Then use that fully qualified path replacing java (at the end) with keytool.然后使用该完全限定的路径用 keytool 替换 java(最后)。 If your path includes space-separated names, such as Program Files, use platform-appropriate notation for the names.如果您的路径包含以空格分隔的名称,例如 Program Files,请使用适合平台的表示法作为名称。 For example, on Mac/Linux use Program\ Files, and on Windows use "Program Files".例如,在 Mac/Linux 上使用 Program\ Files,在 Windows 上使用“Program Files”。 The -storetype JKS tag is only required for Java 9 or newer.只有 Java 9 或更高版本需要 -storetype JKS 标签。 As of the Java 9 release, the keystore type defaults to PKS12从 Java 9 版本开始,密钥库类型默认为 PKS12

1- remove upload-keystore.jks 1-删除上传-keystore.jks

a-  /android/app/upload-keystore.jks
b- /home/user/upload-keystore.jks

2- Regenerate file: 2-重新生成文件:

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

3- copy file /home/user/ upload-keystore.jks to android/app/ 3- 复制文件/home/user/upload-keystore.jks到 android/app/

4- flutter clean 4- flutter clean

5- Flutter build appbundle 5- Flutter build appbundle

This works fine for me:)这对我来说很好:)

/Users/macbookpro/Library/Java/JavaVirtualMachines/openjdk-16.0.1/Contents/Home/bin/keytool -genkey -v -keystore android/app/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS

IF YOU CAN'T/DON'T WANT TO GENERATE NEW KEYS.如果您不能/不想生成新密钥。

Generating new keys was not an option for me because our app is already in production and contacting google was such a hassle.生成新密钥对我来说不是一个选项,因为我们的应用程序已经在生产中并且联系谷歌是如此的麻烦。 As others have pointed out, the build fails because the app was signed with a java version higher than Java 11. But the HmacPBESHA256 algorithm is not available in java 11 which is shipped with Android Studio. As others have pointed out, the build fails because the app was signed with a java version higher than Java 11. But the HmacPBESHA256 algorithm is not available in java 11 which is shipped with Android Studio. That is, Android Studio is trying to build your app with Java 11.也就是说,Android Studio 正在尝试使用 Java 11 构建您的应用程序。

So the solution for me was to get Android Studio to build the aab with my local java version, not java 11. To tell Android Studio which JDK version to use, in gradle.properties , I added: So the solution for me was to get Android Studio to build the aab with my local java version, not java 11. To tell Android Studio which JDK version to use, in gradle.properties , I added:

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home

After this, I was able to build my aab without any issues with the keys I already had.在此之后,我能够构建我的 aab,而我已经拥有的密钥没有任何问题。

I found this problem befor and i solve it when i change the JDK from 11 version to 16 version in windows 10 64bit我之前发现了这个问题,当我在 windows 10 64bit 中将 JDK 从 11 版本更改为 16 版本时解决了这个问题

Like Graciela, I am unable to recreate the certificate.像 Graciela 一样,我无法重新创建证书。 However, I using Java 12+ in Android Studio isn't a good fix for me.但是,我在 Android Studio 中使用 Java 12+ 对我来说并不是一个好的解决方法。 Using an updated Java version works for deploying from my machine, but not from the CI server.使用更新的 Java 版本适用于从我的机器部署,但不适用于从 CI 服务器部署。

Instead, I exported and imported the certificate to change the signing algorithm.相反,我导出并导入了证书以更改签名算法。

Here are the steps I used:以下是我使用的步骤:

Export the certificate to PKCS12 using Java v12+:使用 Java v12+ 将证书导出到 PKCS12:

keytool -importkeystore -srckeystore ./upload-keystore.jks -destkeystore ./pcstore.p12 -deststoretype PKCS12

Using openssl, export the key as.pem使用openssl,将密钥导出为.pem

openssl pkcs12 -nodes -in pcstore.p12 -out keystore.pem

Create a new.p12 store using openssl使用 openssl 创建一个 new.p12 存储

openssl pkcs12 -export -in keystore.pem -out new-pcstore.p12 -name upload

Create a new jks store using the Android Studio version of Java (Java 11) by importing the.p12 store:通过导入.p12 存储,使用 Java (Java 11) 的 Android Studio 版本创建一个新的 jks 存储:

/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool -importkeystore -srckeystore ./new-pcstore.p12 -destkeystore ./new-upload-keystore.jks -deststoretype jks

Now the keystore works with Java 11 and it's using the same certificate I signed the app with before.现在密钥库与 Java 11 一起使用,它使用与我之前签署应用程序的相同证书。

For my case, I have used gradle 7.3 build tool to compile the source.就我而言,我使用了 gradle 7.3 构建工具来编译源代码。 it is worked without any problem.它可以正常工作。

First, download gradle from this link: https://gradle.org/releases/首先,从这个链接下载gradle: https://gradle.org/releases/

Unzip it in your preferred location解压到你喜欢的位置

Than run this command: export PATH=$PATH:/gradle_bin_path比运行这个命令: export PATH=$PATH:/gradle_bin_path

This will add gradle binary for current terminal session only.这将为当前终端 session 添加 gradle 二进制文件。 If you want to add this path for permanent, you need to follow extra step:如果要永久添加此路径,则需要执行额外的步骤:

first run this command to get what terminal you are using:首先运行此命令以获取您正在使用的终端:

echo $SHELL

I am using zsh as shell, so if the output is /bin/zsh than run this following commands:我使用 zsh 作为 shell,所以如果 output 是 /bin/zsh,则运行以下命令:

sudo -s
cd /users/username
ls
vim .zshrc

Before editing the.zshrc file, be sure to have a backup of this file在编辑 .zshrc 文件之前,请务必备份此文件

And than add following line to this file: export PATH=$PATH:/gradle_bin_path并在此文件中添加以下行: export PATH=$PATH:/gradle_bin_path

Save and quit the editor.保存并退出编辑器。

Than run this command: source.zshrc比运行这个命令: source.zshrc

The path list now updated.路径列表现已更新。 Let's run this command:让我们运行这个命令:

gradle --version

It should show current gradle version.它应该显示当前的 gradle 版本。

Now, time to compile the app.现在,是时候编译应用程序了。 lets cd to directory where your project is.让 cd 到您的项目所在的目录。

Then, run this command: gradle clean然后,运行这个命令: gradle clean

Wait till gradle finish sync your project.等到 gradle 完成同步您的项目。 once finish sync, run this command:完成同步后,运行以下命令:

gradle build

Finally, you will be able to solve your problem.最后,您将能够解决您的问题。

AS I lost my Keystore, and was unable to return it back, read google documentation about getting a new key.由于我丢失了我的密钥库,并且无法将其归还,因此请阅读有关获取新密钥的谷歌文档。

Google: If you've lost your private upload key or it's been compromised, you can create a new one, and then ask your account owner to contact support to reset the key. Google:如果您丢失了私有上传密钥或已被泄露,您可以创建一个新的,然后让您的帐户所有者联系支持人员以重置密钥。 When contacting support, make sure your account owner attaches the upload_certificate.pem file.联系支持人员时,请确保您的帐户所有者附加了 upload_certificate.pem 文件。

I emailed google at the following link: https://support.google.com/googleplay/android-developer/contact/key我通过以下链接向谷歌发送电子邮件: https://support.google.com/googleplay/android-developer/contact/key

They sent me the following commands to re-generate keystore and certificate.pem:他们向我发送了以下命令来重新生成密钥库和 certificate.pem:

Here's how to generate and register a new upload key:以下是生成和注册新上传密钥的方法:

Follow the instructions in the Android Studio Help Center to generate a new key.按照 Android Studio 帮助中心中的说明生成新密钥。 It must be different from any previous keys.它必须不同于任何以前的密钥。 Alternatively, you can use the following command line to generate a new key:或者,您可以使用以下命令行生成新密钥:

keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks keytool -genkeypair -alias upload -keyalg RSA -keysize 2048 -validity 9125 -keystore keystore.jks

This key must be a 2048 bit RSA key and have 25-year validity.此密钥必须是 2048 位 RSA 密钥,并且有效期为 25 年。 Export the certificate for that key to PEM format:将该密钥的证书导出为 PEM 格式:

keytool -export -rfc -alias upload -file upload_certificate.pem -keystore keystore.jks keytool -export -rfc -alias upload -file upload_certificate.pem -keystore keystore.jks

Reply to this email and attach the upload_certificate.pem file, after replying, they will send an email mentioning your key store will be updated after 2 days,回复此 email 并附上 upload_certificate.pem 文件,回复后,他们将发送 email 提及您的密钥存储将在 2 天后更新,

now you have a new key store, in order to generate a signed bundle keys, you must do the following:现在您有了一个新的密钥库,为了生成签名的捆绑密钥,您必须执行以下操作:

1- Go to the android side in your flutter (2.8.1) project. 1- Go 到 flutter (2.8.1) 项目中的 android 侧。 2- go to settings> Build, Execution..> Gradle> 3- change gradle JDK to something between 16 and 11, **JDK 15 worked for me. 2- go 到设置>构建,执行..> Gradle> 3-将 gradle JDK 更改为 16 到 11 之间的值,**JDK 15 对我有用。

note: if you don't have jdk, you can download it in same place Gradle JDK with jdk download option.注意:如果你没有 jdk,你可以在同一个地方下载它 Gradle JDK 和 jdk 下载选项。 note: you must build your signed app bundle within android only not inside flutter framework.注意:您必须在 android 内构建您的签名应用程序包,而不是在 flutter 框架内。

Solution is very simple.解决方案非常简单。 Just delete your file mentioned in the error log.只需删除错误日志中提到的文件即可。 For example in my case the path was shown below.例如,在我的情况下,路径如下所示。

C:\Users\kattie\.android\debug.keystore.jks

Delete this debug.keystore.jks file and make sure you close android studio or OpenJDK process from task manager.删除此 debug.keystore.jks 文件并确保从任务管理器中关闭 android studio 或 OpenJDK 进程。

The @azhar-ali answer does not work for me on Ubuntu 2020.04. @azhar-ali 的答案在 Ubuntu 2020.04 上对我不起作用。 And I found this answer that worked.我发现这个答案很有效。

Commands:命令:

keytool -genkey -v -keystore upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS

keytool -importkeystore -srckeystore upload-keystore.jks -destkeystore upload-keystore.p12 -deststoretype PKCS12

openssl pkcs12 -nodes -in upload-keystore.p12 -out upload-keystore.pem

openssl pkcs12 -export -in upload-keystore.pem -out new-upload-keystore.p12 -name upload

(Using p12 key instead of jks key) (使用 p12 键代替 jks 键)

key.properties:关键属性:

storeFile=/home/admin/Documents/Working/projects/new-upload-keystore.p12

Result:结果:

flutter build appbundle

💪 Building with sound null safety 💪

Running Gradle task 'bundleRelease'...                           2,422ms
✓ Built build/app/outputs/bundle/release/app-release.aab (16.6MB).

Add this in last of your command在你的命令的最后添加这个

-storetype JKS -店型JKS

Like,像,

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

Command命令

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

worked for me on my mac m1.在我的 mac m1 上为我工作。

i was using java version 17 and everytime i try to build appbundle i would get error我使用的是 java 版本 17,每次我尝试构建 appbundle 时都会出错

Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available完整性检查失败:java.security.NoSuchAlgorithmException:算法 HmacPBESHA256 不可用

To solve this i added为了解决这个问题,我添加了

-deststoretype JKS in keytool command and it worked for me. -deststoretype JKS 在 keytool 命令中,它对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 版本:完整性检查失败:java.security.NoSuchAlgorithmException:算法 HmacPBESHA256 不可用 - Java Versions: Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available 算法 HmacPBESHA256 不可用(Flutter 构建失败) - Algorithm HmacPBESHA256 not available (Flutter Build Failed) 算法 HmacPBESHA256 不可用 - Algorithm HmacPBESHA256 not available 算法“HmacPBESHA256”不可用,那是什么? - Algorithm "HmacPBESHA256" is not available and what is that? java.security.NoSuchAlgorithmException:算法PBKDF2WithHmacSHA1不可用 - java.security.NoSuchAlgorithmException: Algorithm PBKDF2WithHmacSHA1 not available java.security.NoSuchAlgorithmException:算法 x25519 不可用 - java.security.NoSuchAlgorithmException: Algorithm x25519 not available java.security.NoSuchAlgorithmException: RSA 签名不可用 - java.security.NoSuchAlgorithmException: RSA Signature not available .java.security.NoSuchAlgorithmException:提供者Cryptix不提供算法RSA / PKCS1 - .java.security.NoSuchAlgorithmException: algorithm RSA/PKCS1 is not available from provider Cryptix Java 9使用“java.security.NoSuchAlgorithmException:SHA3-384 MessageDigest不可用” - “java.security.NoSuchAlgorithmException: SHA3-384 MessageDigest not available” with Java 9 java.security.NoSuchAlgorithmException: RIPEMD160 MessageDigest 不可用 - java.security.NoSuchAlgorithmException: RIPEMD160 MessageDigest not available
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM