website icon indicating copy to clipboard operation
website copied to clipboard

HmacPBESHA256 not available.

Open rongpenl opened this issue 3 years ago • 28 comments

Page URL: https://flutter.dev/docs/deployment/android.html Page source: https://github.com/flutter/website/tree/master/src/docs/deployment/android.md

Found a typo? You can fix it yourself by going to the page source and clicking the pencil icon. Or finish creating this issue.

Description of issue:

It looks like the latest Android Studio has builtin java 11. And HmacPBESHA256 is only supported starting with java 12. See this stackoverflow question.

Therefore the following error happens when running flutter build appbundle.

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/ronli/upload-keystore.jks": Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available

rongpenl avatar May 28 '21 22:05 rongpenl

It looks like changing genkey to genkeypair works.

rongpenl avatar May 28 '21 23:05 rongpenl

i still facing this issue, genkeypair not working for me. Show same error.. please help..

Alhaadi-IDB avatar Jun 05 '21 10:06 Alhaadi-IDB

I'm having the same issue. I tried just about everything to resolve it for the past 5 hours. But it simply persists. I read that the Java version shipped with Android Studio doesn't have the SHA-256 algorithm. Help would be much appreciated.

Shyam-Sundar-Bharathi avatar Jun 05 '21 20:06 Shyam-Sundar-Bharathi

I Solved my problem after about 2 weeks facing this issue, turn out my MAC java is java 18 and android studio default run java 11, so i change my MAC java Home path to run java 11, then run flutter clean create the file keystroke again, then all good now.

Alhaadi-IDB avatar Jun 07 '21 05:06 Alhaadi-IDB

@Alhaadi-IDB Interesting because java 11 didn't have that algorithm. Can you provide more details? What's the output of this command on your machine?

/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/java --version

FYI for whoever reads the issue, this is the StackOverflow question: https://stackoverflow.com/questions/67631927/error-building-aab-flutter-android-integrity-check-failed-java-security-n/67632064?noredirect=1#comment119760622_67632064

rongpenl avatar Jun 07 '21 16:06 rongpenl

@Alhaadi-IDB Interesting because java 11 didn't have that algorithm. Can you provide more details? What's the output of this command on your machine?

/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/java --version

FYI for whoever reads the issue, this is the StackOverflow question: https://stackoverflow.com/questions/67631927/error-building-aab-flutter-android-integrity-check-failed-java-security-n/67632064?noredirect=1#comment119760622_67632064

Yes. This works. That's the first thing I saw, however, for some reason, I decided to try everything in the world for 1 entire night before finally trying that and it works like a charm.

Shyam-Sundar-Bharathi avatar Jun 07 '21 17:06 Shyam-Sundar-Bharathi

@Alhaadi-IDB That's one way to do it but in my opinion, I'm not sure if it's the best way. So basically by switching to Java 11, you're using a less secure version of SHA which may be a security threat. SHA256withRSA is advisable, but only available from after Java 12. I don't know if the Stack Overflow solution uses SHA256 either, but the terminal warns when we use lesser encryption and that didn't happen. So I'm assuming that's the best option.

Shyam-Sundar-Bharathi avatar Jun 07 '21 18:06 Shyam-Sundar-Bharathi

Hi all,

as I think I had the same issue. I now tried the command keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS with the addtional -storetype JKS and it worked. In the docs, there is only the version without this parameter for Mac/Linux specified. Omitting this option leads to the same error (https://github.com/flutter/website/issues/5871#issue-906178960) above.

Akkamar avatar Jun 16 '21 13:06 Akkamar

If you are still facing this issue, Update Android Studio IDE to the latest version 4.2 and regenerate the jks file again then build your apk or appbundle. and the issue will not appear again. Steps to update Android Studio In the main page of Android Studio go to this path

Configure/Preferences/Appearance & Behavior/System Settings/Updates

and press Check Now for checking any updates

moatazfouad avatar Jun 16 '21 14:06 moatazfouad

@rongpenl Is this still a valid issue or does https://github.com/flutter/website/issues/5871#issuecomment-855597669 or above solutions helps to resolve this ?

darshankawar avatar Jul 29 '21 11:07 darshankawar

Hi @darshankawar,

I am not actively monitoring this issue. Sorry for the late reply. I solved the issue on my side with a different way ( as I replied earlier). I guess there are many ways to solve this issue. An update or "warning" on the official site is probably helpful.

rongpenl avatar Aug 11 '21 03:08 rongpenl

An update or "warning" on the official site is probably helpful.

Labeling per above comment.

darshankawar avatar Aug 11 '21 05:08 darshankawar

@Alhaadi-IDB Interesting because java 11 didn't have that algorithm. Can you provide more details? What's the output of this command on your machine?

/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/java --version

FYI for whoever reads the issue, this is the StackOverflow question: https://stackoverflow.com/questions/67631927/error-building-aab-flutter-android-integrity-check-failed-java-security-n/67632064?noredirect=1#comment119760622_67632064

This worked for me after struggling for hours.

KhalidWar avatar Aug 27 '21 21:08 KhalidWar

I generated keys at the start of the project and they worked fine until recently I got this error.

I was able to generate a new key successfully to sign my app bundle. The problem is now when I upload it to the Android play console I get "Your Android App Bundle is signed with the wrong key...."

So generating new keys is not a valid solution for me since my app is already in production.

Is there a way to add HmacPBESHA256 to an already existing key?

chris-otani avatar Sep 22 '21 22:09 chris-otani

Hi everyone, I got the same issue yesterday. I deleted my old debug key, which is located at /Users/<username>/.android/debug.keystore. Hope this helps. Thanks.

shirishkoirala avatar Sep 26 '21 19:09 shirishkoirala

I generated keys at the start of the project and they worked fine until recently I got this error.

I was able to generate a new key successfully to sign my app bundle. The problem is now when I upload it to the Android play console I get "Your Android App Bundle is signed with the wrong key...."

So generating new keys is not a valid solution for me since my app is already in production.

Is there a way to add HmacPBESHA256 to an already existing key?

I faced the same problem. I tried all the suggested methods, nothing helps. I just can't release an update to the application.

BarNce avatar Oct 25 '21 11:10 BarNce

I generated keys at the start of the project and they worked fine until recently I got this error. I was able to generate a new key successfully to sign my app bundle. The problem is now when I upload it to the Android play console I get "Your Android App Bundle is signed with the wrong key...." So generating new keys is not a valid solution for me since my app is already in production. Is there a way to add HmacPBESHA256 to an already existing key?

I faced the same problem. I tried all the suggested methods, nothing helps. I just can't release an update to the application.

I gave up and finally had to email google my new keys and have them update them.

chris-otani avatar Oct 25 '21 16:10 chris-otani

@chris-otani Like you, generating new keys was not an option 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.

So the solution was to get Android Studio to build the aab with your local java version, not java 11. To specify the JDK version, in gradle.properties, I added:

org.gradle.java.home=/Library/Java/JavaVirtualMachines/jdk-15.0.2.jdk/Contents/Home <- Substitute with your java home path

After this, I was able to build my aab without any issues with the keys I already had.

gracecarrillo avatar Nov 06 '21 15:11 gracecarrillo

@gracecarrillo It turned out to be impossible to contact google support. Your answer completely solved my problem. Thanks!

BarNce avatar Nov 08 '21 03:11 BarNce

Just change the settings of Android Studio; change the Gradle JDK to higher version from default java 11. And then the problem can be solved. image

Childe-Tartaglia avatar Nov 18 '21 10:11 Childe-Tartaglia

Hi all,

as I think I had the same issue. I now tried the command keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS with the addtional -storetype JKS and it worked. In the docs, there is only the version without this parameter for Mac/Linux specified. Omitting this option leads to the same error (#5871 (comment)) above.

I have spent quite a lot of time on this. Nothing was working for me. What worked for me was: -deststoretype JKS

instead of: -storetype JKS

alymbouras avatar Feb 19 '22 12:02 alymbouras

I Solved my problem after about 2 weeks facing this issue, turn out my MAC java is java 18 and android studio default run java 11, so i change my MAC java Home path to run java 11, then run flutter clean create the file keystroke again, then all good now.

@Alhaadi-IDB Thank you! This is what worked for me.

I am using zsh and in Mac OS Catalina so I edited .zshrc by adding

export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home/"

save it, close existing terminals and open again to check versions if they are the same already flutter doctor -v java --version

Then I went to add key in /android/app/ (added in .gitignore) keytool -genkey -v -keystore key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

Added key.properties in /android (added in .gitignore):

storePassword=pwhere
keyPassword=pwhere
keyAlias=key
storeFile=key.jks

Then flutter clean

Then flutter build appbundle

With result:

Changing current working directory to: /Users/name/flutterapp
Running "flutter pub get" in flutterapp...                    2,102ms

💪 Building with sound null safety 💪

/Users/name/flutterapp/android/key.properties
Removed unused resources: Binary resource data reduced from 556KB to 486KB: Removed 12%
Running Gradle task 'bundleRelease'...                            107.9s
✓ Built build/app/outputs/bundle/release/app-release.aab (20.3MB).

arvi avatar Feb 22 '22 15:02 arvi

facing same issue

sohaibqureshi234 avatar Feb 28 '22 12:02 sohaibqureshi234

  • What went wrong: Execution failed for task ':app:packageDebug'.

A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable com.android.ide.common.signing.KeytoolException: Failed to read key AndroidDebugKey from store "C:\Users\annonymous.android\debug.keystore": Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available

sohaibqureshi234 avatar Feb 28 '22 12:02 sohaibqureshi234

Akkama

Hi, I am so thankful. I have tried many things before but it did not work. You saved my life ❤

MohammedFouadx avatar Apr 08 '22 00:04 MohammedFouadx

Just change / set the gradle.properties option org.gradle.java.home.

If you are using Arch Linux, it's as easy as:

org.gradle.java.home=/usr/lib/jvm/default

denysvitali avatar May 08 '22 12:05 denysvitali

I Solved my problem after about 2 weeks facing this issue, turn out my MAC java is java 18 and android studio default run java 11, so i change my MAC java Home path to run java 11, then run flutter clean create the file keystroke again, then all good now.

And how did you do that? I think im facing the same issue

AliJ91 avatar May 31 '22 15:05 AliJ91

I Solved my problem after about 2 weeks facing this issue, turn out my MAC java is java 18 and android studio default run java 11, so i change my MAC java Home path to run java 11, then run flutter clean create the file keystroke again, then all good now.

And how did you do that? I think im facing the same issue

Make sure ur java HOME version is similar with the java version use in Android Studio. Can google on how to check and set the java version for ur OS and Android studio.

Alhaadi-IDB avatar Jun 08 '22 07:06 Alhaadi-IDB

This issue has been documented at https://docs.flutter.dev/release/breaking-changes/android-java-gradle-migration-guide to cover a similar situation. Fixed in https://github.com/flutter/website/pull/8501. Closing this issue.

atsansone avatar Jun 02 '23 04:06 atsansone