diff --git a/packages/package_info_plus/package_info_plus/android/build.gradle b/packages/package_info_plus/package_info_plus/android/build.gradle index f03c20d32f..25ebf86b61 100644 --- a/packages/package_info_plus/package_info_plus/android/build.gradle +++ b/packages/package_info_plus/package_info_plus/android/build.gradle @@ -23,7 +23,19 @@ rootProject.allprojects { } apply plugin: 'com.android.library' -apply plugin: 'kotlin-android' + +// Built-in Kotlin migration (AGP 9): AGP 9 removes support for applying the Kotlin Gradle +// Plugin (KGP) directly and provides built-in Kotlin instead. Apply KGP only when built-in +// Kotlin is NOT active — i.e. on AGP < 9, or when `android.builtInKotlin` is disabled (the +// Flutter transition default, which Flutter still sets to false even on AGP 9). This keeps the +// plugin building across both the legacy-KGP and built-in-Kotlin paths, and stops applying KGP +// once the host enables built-in Kotlin on AGP 9+. +// 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 builtInKotlin = providers.gradleProperty('android.builtInKotlin').map { it.toBoolean() }.orElse(agpMajor >= 9).get() +if (agpMajor < 9 || !builtInKotlin) { + apply plugin: 'kotlin-android' +} android { namespace 'dev.fluttercommunity.plus.packageinfo' @@ -34,10 +46,6 @@ android { targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = 17 - } - defaultConfig { minSdk 19 testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" @@ -51,3 +59,12 @@ android { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } } + +// Replaces the deprecated `kotlinOptions { jvmTarget = ... }` block, which is removed alongside +// KGP under built-in Kotlin. The `kotlin` extension is registered by KGP on AGP < 9 and by +// built-in Kotlin on AGP 9+, so this configures the Kotlin compiler on both. +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} diff --git a/packages/package_info_plus/package_info_plus/example/android/app/build.gradle b/packages/package_info_plus/package_info_plus/example/android/app/build.gradle index fb70d7caf2..4637e93607 100644 --- a/packages/package_info_plus/package_info_plus/example/android/app/build.gradle +++ b/packages/package_info_plus/package_info_plus/example/android/app/build.gradle @@ -1,6 +1,5 @@ plugins { id "com.android.application" - id "kotlin-android" id "dev.flutter.flutter-gradle-plugin" } @@ -31,10 +30,6 @@ android { targetCompatibility JavaVersion.VERSION_17 } - kotlinOptions { - jvmTarget = 17 - } - sourceSets { main.java.srcDirs += 'src/main/kotlin' } @@ -60,6 +55,12 @@ android { } } +kotlin { + compilerOptions { + jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17 + } +} + flutter { source '../..' }