[Flutter] Android Studio「Ladybug」で「Your project’s Gradle version is incompatible with the Java version that Flutter is using for Gradle・・・」エラー発生時の対処法

このページには広告が含まれる場合があります。

 

10月にAndroid Studioが「Ladybug」というバージョンにアップデートされました。

その1つ前のバージョンは「Koala」でしたが、「Koala」の時は普通に動いていたFlutterのプロジェクトが、「Ladybug」にアップデートしたことでAndroidアプリとしてデバッグ実行しようとすると、こんなエラーが発生する可能性があります。

FAILURE: Build failed with an exception.

* What went wrong:
Could not open cp_settings generic class cache for settings file 'C:\Users\keybo\FlutterProjects\straight_machine\android\settings.gradle' (C:\Users\keybo\.gradle\caches\7.5\scripts\2k55299xwicywd34chg69jwy4).
> BUG! exception in phase 'semantic analysis' in source unit '_BuildScript_' Unsupported class file major version 65

* 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 10s

┌─ 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/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\keybo\FlutterProjects\straight_machine\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                                │
│                                                                                                  │
│                                                                                                  │
└──────────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1

「Your project's Gradle version is incompatible with the Java version」のエラーが出た画面

このエラーメッセージは、Flutterが使用している Gradleのバージョン と Javaバージョン の互換性が取れていないという意味なので、以下の要領で修正すれば大丈夫です。

1)以下の要領でFlutterのプロジェクトをAndroidアプリとして開く

Android Studioで、android直下のbuild.gradleを右クリックし「Open In」から「Open In Associated Application」を選ぶ手順

2)すると、以下のようなエラーメッセージが出てビルドに失敗するので

Your build is currently configured to use imcompatible Java 21.0.3 and Gradle 7.5. Cannot sync the project.

「Your build is currently configured to use incompatible Java 21.0.3 and Gradle 7.5」のエラー画面

 

3)エラーメッセージの最下部にある「upgrade to Gradle 8.5 and re-sync」を押下

エラーメッセージの「Upgrade to Gradle 8.5 and re-sync」を押す(8.9より8.5が無難)

(注)ここで「8.9」を選択すると、私の経験上思わぬエラーが発生する可能性があるので、「8.5」にしておいた方が無難かと思われます。

 

4)「Gradle Sync Needed」というエラーが出て、Gradleの再同期を求められるので、指示に従って「Sync Project」押下

「Gradle Sync Needed」の通知で「Sync Project」を押す

 

5)同期完了後、「Project update recommended」というメッセージが出て、Gradleプラグインのバージョンを上げることを求められるので「Start AGP Upgrade Assistant」を押下

「Project update recommended」の通知で「Start AGP Upgrade Assistant」を押す

6)あとは、画面の指示に従って、言われるがままのバージョンで「Run selected steps」してプラグインをアップグレード。

Upgrade Assistantで、示されたバージョンのまま「Run selected steps」を押す画面

するとエラーが解消します。

 

(詳しくは、以下の動画で説明していますので、よろしければご覧ください)

こんな記事も読まれています

【無料】生年月日を入力するだけ!

あなたの知らない「あなた」がわかる
無料診断ツール

あすコロ式
使命・性格タイプ診断

生年月日を入力するだけで144通りの性格パターンを診断。あなたの知らない「本当のあなた(生きる目的・使命)」と「偽りのあなた(無意識の思いグセ)」がわかります!

今すぐ無料で診断する ▶

TOP