flutter build appbundleでAlgorithm HmacPBESHA256 not availableエラー


Google Play Storeにアプリをリリースするために、flutter build appbundleでappbundleを作ろうとしたら、下記エラーが発生した。

(base) username@pcname app_name % flutter build appbundle

💪 Building with sound 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.FinalizeBundleTask$BundleToolRunnable
   > Failed to read key upload from store "flutterProject/app_name/android/upload-keystore.jks": Integrity check failed: java.security.NoSuchAlgorithmException: Algorithm HmacPBESHA256 not available

* 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 4s
Running Gradle task 'bundleRelease'...                              5.4s
Gradle task bundleRelease failed with exit code 1

jksキーファイルは、Flutter公式のBuild and release an Android appに沿って、

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

としていた(Mac)。

公式にNoteで、

The -storetype JKS tag is only required for Java 9 or newer. As of the Java 9 release, the keystore type defaults to PKS12.

と記載があったため、末尾に-storetype JKSをつけた以下のコマンドを実行すると成功した。

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

結果は以下の通り。

(base) username@pcname app_name %   keytool -genkey -v -keystore ~/upload-keystore.jks -keyalg RSA -keysize 2048 -validity 10000 -alias upload -storetype JKS
Enter keystore password:  
Re-enter new password: 
What is your first and last name?
  [Unknown]:  
What is the name of your organizational unit?
  [Unknown]:  personal
What is the name of your organization?
  [Unknown]:  
What is the name of your City or Locality?
  [Unknown]:  
What is the name of your State or Province?
  [Unknown]:  
What is the two-letter country code for this unit?
  [Unknown]:  JP
Is CN=, OU=personal, O=, L=, ST=, C=JP correct?
  [no]:  yes

Generating 2,048 bit RSA key pair and self-signed certificate (SHA256withRSA) with a validity of 10,000 days
        for: CN=, OU=personal, O=, L=, ST=, C=JP
Enter key password for <upload>
        (RETURN if same as keystore password):  
[Storing /Users/username/upload-keystore.jks]

Warning:
The JKS keystore uses a proprietary format. It is recommended to migrate to PKCS12 which is an industry standard format using "keytool -importkeystore -srckeystore /Users/username/upload-keystore.jks -destkeystore /Users/username/upload-keystore.jks -deststoretype pkcs12".
(base) username@pcname app_name % 
(base) username@pcname app_name % flutter build appbundle

💪 Building with sound null safety 💪

Running Gradle task 'bundleRelease'...                              7.0s
✓ Built build/app/outputs/bundle/release/app-release.aab (24.7MB).
(base) username@pcname app_name % 

参考