エラー
Launching lib/main.dart on sdk gphone64 arm64 in debug mode...
...
~略~ was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.1.0, expected version is 1.8.0.
...
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
* 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 49s
┌─ Flutter Fix ────────────────────────────────────────────────────────────────────────────────┐
│ [!] Your project requires a newer version of the Kotlin Gradle plugin. │
│ Find the latest version on https://kotlinlang.org/docs/releases.html#release-details, then │
│ update the │
│ version number of the plugin with id "org.jetbrains.kotlin.android" in the plugins block of │
│ /path/to/android/settings.gradle. │
│ │
│ Alternatively (if your project was created before Flutter 3.19), update │
│ /path/to/android/build.gradle │
│ ext.kotlin_version = '<latest-version>' │
└──────────────────────────────────────────────────────────────────────────────────────────────┘
Error: Gradle task assembleDebug failed with exit code 1
Exited (1).
原因
The binary version of its metadata is 2.1.0, expected version is 1.8.0.
incompatibleなkotlinのバージョンでコンパイルしていることが原因の模様。
解決方法
エラーメッセージの通りに、まずは kotlin のバージョンを確認する
https://kotlinlang.org/docs/releases.html#release-details
次に、android/settings.gradle
でバージョンを指定する
Before
// android/settings.gradle
plugins {
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}
After
// android/settings.gradle
plugins {
id "org.jetbrains.kotlin.android" version "2.1.10" apply false
}
エラーメッセージには 2.1.0
とあったが、執筆時点での最新バージョンは 2.1.10
だったため、こちらを指定してみた。
その後ビルドしたところビルドに成功しました🎉