From f5d2d52d0beaae180c7f6874373f3564f537ec00 Mon Sep 17 00:00:00 2001 From: Nogringo Date: Mon, 6 Jul 2026 02:42:09 +0200 Subject: [PATCH] fix(ndk_flutter): migrate Android plugin to Built-in Kotlin Apply the Kotlin Gradle Plugin only on AGP < 9 so Flutter 3.44+ stops flagging ndk_flutter as applying KGP and future Flutter versions keep building. The conditional stays on one line so Flutter's source-level detection does not re-trigger the warning. Replace the deprecated kotlinOptions block with kotlin { compilerOptions }, which also works under AGP 9. Remains compatible with Flutter < 3.44. --- packages/ndk_flutter/android/build.gradle | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/ndk_flutter/android/build.gradle b/packages/ndk_flutter/android/build.gradle index 6312bb6fd..deaf7fcd8 100644 --- a/packages/ndk_flutter/android/build.gradle +++ b/packages/ndk_flutter/android/build.gradle @@ -21,7 +21,11 @@ allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' + +// AGP 9+ bundles Kotlin (Flutter Built-in Kotlin); only apply KGP ourselves on older AGP. +// Must stay on one line: Flutter's detection flags any line starting with `apply plugin: 'kotlin-android'`. +def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0] as int +if (agpMajor < 9) { apply plugin: 'kotlin-android' } android { if (project.android.hasProperty("namespace")) { @@ -35,10 +39,6 @@ android { targetCompatibility = JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = '17' - } - sourceSets { main.java.srcDirs += 'src/main/kotlin' test.java.srcDirs += 'src/test/kotlin' @@ -67,6 +67,12 @@ android { } } +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} + subprojects { afterEvaluate { project -> if (project.extensions.findByName("android") != null) {