Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions packages/package_info_plus/package_info_plus/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -34,10 +46,6 @@ android {
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = 17
}

defaultConfig {
minSdk 19
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand All @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "dev.flutter.flutter-gradle-plugin"
}

Expand Down Expand Up @@ -31,10 +30,6 @@ android {
targetCompatibility JavaVersion.VERSION_17
}

kotlinOptions {
jvmTarget = 17
}

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
Expand All @@ -60,6 +55,12 @@ android {
}
}

kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}

flutter {
source '../..'
}
Expand Down
Loading