Skip to content

Commit d031c3f

Browse files
authored
chore(android): support AGP 9 built-in Kotlin (#1102)
## Summary Migrates the Android plugin to AGP 9's built-in Kotlin while keeping older toolchains building (same pattern as flutter-webrtc/flutter-webrtc#2075): - Apply the **Kotlin Gradle Plugin only when built-in Kotlin is inactive** — AGP < 9, or AGP 9 with `android.builtInKotlin=false` (the configuration Flutter currently ships by default while the ecosystem migrates). When AGP 9's built-in Kotlin is active it registers the `kotlin` extension itself and rejects KGP, so applying it is skipped. - Set the JVM target through the `kotlin { compilerOptions {} }` DSL **when the extension supports it** (KGP 1.9+ / AGP 9 built-in Kotlin), falling back to the legacy `kotlinOptions` DSL for apps still on KGP 1.8.x. - Bump the standalone buildscript fallback KGP to 2.1.0 so it is self-consistent. - Add a changeset entry for the generated release notes. ## Context AGP 9 uses built-in Kotlin support and rejects Android plugins that still apply KGP directly. This follows the Flutter compatibility migration path instead of raising the minimum supported toolchain. ## Verification - Example app builds (`flutter build apk --debug`) on the current stable toolchain (AGP 8.x + modern KGP path). - The AGP 9 built-in path mirrors the reviewed and merged flutter-webrtc implementation.
1 parent b6cc65d commit d031c3f

2 files changed

Lines changed: 30 additions & 6 deletions

File tree

.changes/agp9-built-in-kotlin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Android plugin compatibility with AGP 9 built-in Kotlin"

android/build.gradle

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ group = "io.livekit.plugin"
22
version = "1.0-SNAPSHOT"
33

44
buildscript {
5-
ext.kotlin_version = "1.8.22"
5+
ext.kotlin_version = "2.1.0"
66
repositories {
77
google()
88
mavenCentral()
@@ -22,7 +22,18 @@ allprojects {
2222
}
2323

2424
apply plugin: "com.android.library"
25-
apply plugin: "kotlin-android"
25+
26+
// AGP 9's built-in Kotlin compiles Kotlin itself and rejects the Kotlin Gradle
27+
// Plugin. Apply KGP only when built-in Kotlin is NOT active: that means AGP < 9,
28+
// or AGP 9 with android.builtInKotlin=false (the configuration Flutter currently
29+
// ships by default while the ecosystem migrates).
30+
def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize(".")[0] as int
31+
def builtInKotlinActive = agpMajor >= 9 &&
32+
(!project.hasProperty("android.builtInKotlin") ||
33+
Boolean.parseBoolean(project.property("android.builtInKotlin").toString()))
34+
if (!builtInKotlinActive) {
35+
apply plugin: "kotlin-android"
36+
}
2637

2738
android {
2839
if (project.android.hasProperty("namespace")) {
@@ -36,10 +47,6 @@ android {
3647
targetCompatibility = JavaVersion.VERSION_1_8
3748
}
3849

39-
kotlinOptions {
40-
jvmTarget = JavaVersion.VERSION_1_8
41-
}
42-
4350
sourceSets {
4451
main.java.srcDirs += "src/main/kotlin"
4552
test.java.srcDirs += "src/test/kotlin"
@@ -68,3 +75,19 @@ android {
6875
}
6976
}
7077
}
78+
79+
// Configure the Kotlin JVM target. The compilerOptions DSL requires KGP 1.9+ or
80+
// AGP 9 built-in Kotlin; older Flutter app templates ship KGP 1.8.x, which only
81+
// supports the legacy kotlinOptions DSL.
82+
def kotlinExt = project.extensions.findByName("kotlin")
83+
if (kotlinExt?.hasProperty("compilerOptions")) {
84+
kotlin {
85+
compilerOptions {
86+
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
87+
}
88+
}
89+
} else {
90+
android.kotlinOptions {
91+
jvmTarget = JavaVersion.VERSION_1_8.toString()
92+
}
93+
}

0 commit comments

Comments
 (0)