From 9f0a9317d328b58f8dd55173abd38ce1db80cfd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A5=98=EC=A4=80=EC=98=81?= Date: Fri, 28 Aug 2026 17:50:39 +0900 Subject: [PATCH] Support AGP 9 built-in Kotlin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit AGP 9 ships built-in Kotlin support and registers its own `kotlin { }` extension. Unconditionally applying the classic 'kotlin-android' plugin on top of it fails ("no longer required for Kotlin support since AGP 9"), which currently blocks apps that adopt AGP 9 with built-in Kotlin enabled from depending on this plugin. Only apply 'kotlin-android' when it's actually needed: on AGP < 9, or on AGP 9+ where the app has explicitly opted out via `android.builtInKotlin=false` (Flutter's current recommended interim state for AGP 9 adopters). Move the jvmTarget configuration to the top-level `kotlin { compilerOptions { } }` block per Flutter's plugin migration guide, since that extension is present in both cases. Verified against a real Flutter app on AGP 9.0.1 / Gradle 9.1.0 with `android.builtInKotlin=false` (today's supported "opt-out" combination) — `flutter build appbundle --release` succeeds with this change, with no change in output versus the current published version. The `builtInKotlin=true` path (Flutter 3.47+) follows AGP's documented built-in Kotlin behavior but wasn't independently build-tested since it requires a newer Flutter SDK than what's available in the test app. See https://docs.flutter.dev/release/breaking-changes/migrate-to-built-in-kotlin/for-plugin-authors --- android/build.gradle | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index a37bb9678..16d294d76 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -25,7 +25,17 @@ rootProject.allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' + +// AGP 9+ ships built-in Kotlin support and registers its own `kotlin { }` extension, +// which conflicts with the classic 'kotlin-android' plugin unless the app has opted +// out via `android.builtInKotlin=false` in gradle.properties (Flutter's current +// recommended interim state; see 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 +def builtInKotlinOptedOut = project.hasProperty('android.builtInKotlin') && + !Boolean.parseBoolean(project.property('android.builtInKotlin').toString()) +if (agpMajor < 9 || builtInKotlinOptedOut) { + apply plugin: 'kotlin-android' +} android { namespace "dev.note11.flutter_naver_map.flutter_naver_map" @@ -37,10 +47,6 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - kotlinOptions { - jvmTarget = '1.8' - } - sourceSets { main.java.srcDirs += 'src/main/kotlin' } @@ -54,3 +60,9 @@ android { implementation 'com.google.android.gms:play-services-location:21.3.0' } } + +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8 + } +}