0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Flutter] Androidアプリのビルド時に Your project requires a newer version of the Kotlin Gradle plugin. のエラーが発生した

Posted at

エラー

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 だったため、こちらを指定してみた。

スクリーンショット 2025-02-09 17.24.57.png

その後ビルドしたところビルドに成功しました🎉

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?