From 9a04639faf458bf1880489898a701b055b8e59e9 Mon Sep 17 00:00:00 2001 From: "BDE (local verification)" Date: Sat, 11 Jul 2026 11:40:01 +0900 Subject: [PATCH] Migrate away from unconditionally applying the Kotlin Gradle Plugin (#636) Flutter 3.44+ deprecates plugins that apply KGP themselves, and AGP 9 removes support for it (built-in Kotlin). Per the official plugin-author migration guide (https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors), apply kotlin-android only when the consuming app's AGP major version is below 9, and replace the android.kotlinOptions block with the kotlin.compilerOptions DSL (requires KGP >= 2.0, already satisfied by kotlin_version 2.2.20). The conditional keeps the plugin buildable for apps on older stable Flutter/AGP versions. --- android/build.gradle | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index be7cd9d4..5b646ee0 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -28,7 +28,15 @@ project.getTasks().withType(JavaCompile).configureEach { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' + +// Migration to built-in Kotlin (Flutter 3.44+ / AGP 9 deprecation of plugins +// applying the Kotlin Gradle Plugin themselves). AGP 9+ provides built-in +// Kotlin, so only apply KGP for apps still on older AGP versions, per +// https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors +def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int +if (agpMajor < 9) { + apply plugin: 'kotlin-android' +} android { compileSdk 36 @@ -51,10 +59,14 @@ android { targetCompatibility = JavaVersion.VERSION_11 } - kotlinOptions { - jvmTarget = JavaVersion.VERSION_11 +} + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_11 } } + dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" }