開発環境
flutter doctor
[√] Flutter (Channel stable, 3.29.3, on Microsoft Windows [Version 10.0.26100.4484], locale ja-JP)
[√] Windows Version (11 Home 64-bit, 24H2, 2009)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.5)
[√] Android Studio (version 2024.3.2)
[√] IntelliJ IDEA Community Edition (version 2023.1)
[√] VS Code (version 1.102.1)
[√] Connected device (3 available)
[√] Network resources
• No issues found!
経緯
flutterで作成したアプリをビルドしようとしたら次のようなエラーが出た。今回はこのエラーの解決にかなりの時間を費やしてしまったので記録として残します。
エラー本文
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':image_picker_android:generateReleaseLintModel'.
> Could not resolve all files for configuration ':image_picker_android:releaseUnitTestRuntimeClasspath'.
> Failed to transform bcprov-jdk18on-1.78.1.jar (org.bouncycastle:bcprov-jdk18on:1.78.1) to match attributes {artifactType=processed-jar, org.gradle.category=library, org.gradle.libraryelements=jar, org.gradle.status=release, org.gradle.usage=java-runtime}.
> Execution failed for JetifyTransform: C:\Users\krand\.gradle\caches\modules-2\files-2.1\org.bouncycastle\bcprov-jdk18on\1.78.1\39e9e45359e20998eb79c1828751f94a818d25f8\bcprov-jdk18on-1.78.1.jar.
> Failed to transform 'C:\Users\krand\.gradle\caches\modules-2\files-2.1\org.bouncycastle\bcprov-jdk18on\1.78.1\39e9e45359e20998eb79c1828751f94a818d25f8\bcprov-jdk18on-1.78.1.jar' using Jetifier. Reason: IllegalArgumentException, message: Unsupported class file major version 65. (Run with --stacktrace for more details.)
Suggestions:
- Check out existing issues at https://issuetracker.google.com/issues?q=componentid:460323&s=modified_time:desc, it's possible that this issue has already been filed there.
- If this issue has not been filed, please report it at https://issuetracker.google.com/issues/new?component=460323 (run with --stacktrace and provide a stack trace if possible).
* 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 1m 11s
Running Gradle task 'assembleRelease'... 72.1s
┌─ Flutter Fix ──────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project's Gradle version is incompatible with the Java version that Flutter is using for Gradle. │
│ │
│ If you recently upgraded Android Studio, consult the migration guide at │
│ https://flutter.dev/to/java-gradle-incompatibility. │
│ │
│ Otherwise, to fix this issue, first, check the Java version used by Flutter by running `flutter doctor --verbose`. │
│ │
│ Then, update the Gradle version specified in │
│ C:\Users\krand\Desktop\app\android\gradle\wrapper\gradle-wrapper.properties to be compatible with that Java │
│ version. See the link below for more information on compatible Java/Gradle versions: │
│ https://docs.gradle.org/current/userguide/compatibility.html#java │
│ │
│ │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
Gradle task assembleRelease failed with exit code 1
解決方法
特に古いライブラリ等を使用していなければJetifierを無効化するだけ収まります。
/android/gradle.properties
org.gradle.jvmargs=-Xmx6G
android.useAndroidX=true
- android.enableJetifier=true
+ android.enableJetifier=false
変更後に再ビルド
flutter clean && flutter pub get && flutter build apk
なぜ解決に時間がかかったのか
ERROR→AIに丸投げをしていたらJDKのエラーだと勘違いしてしまい、JDKのバージョンをゴニョゴニョしていたからである。また、「Jetifier無効化って大丈夫なの?」という疑問が残り続け、なかなかこの手段を試していませんでした。やってみるもんですね!