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.5\scriptsk55299xwicywd34chg69jwy4). > 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
このエラーメッセージは、Flutterが使用している Gradleのバージョン と Javaバージョン の互換性が取れていないという意味なので、以下の要領で修正すれば大丈夫です。
1)以下の要領でFlutterのプロジェクトをAndroidアプリとして開く
2)すると、以下のようなエラーメッセージが出てビルドに失敗するので
3)エラーメッセージの最下部にある「upgrade to Gradle 8.5 and re-sync」を押下
4)「Gradle Sync Needed」というエラーが出て、Gradleの再同期を求められるので、指示に従って「Sync Project」押下
5)同期完了後、「Project update recommended」というメッセージが出て、Gradleプラグインのバージョンを上げることを求められるので「Start AGP Upgrade Assistant」を押下
6)あとは、画面の指示に従って、言われるがままのバージョンで「Run selected steps」してプラグインをアップグレード。
するとエラーが解消します。
(詳しくは、以下の動画で説明していますので、よろしければご覧ください)