Skip to content
Merged
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
1 change: 1 addition & 0 deletions .changes/agp9-built-in-kotlin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
patch type="fixed" "Android plugin compatibility with AGP 9 built-in Kotlin"
35 changes: 29 additions & 6 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ group = "io.livekit.plugin"
version = "1.0-SNAPSHOT"

buildscript {
ext.kotlin_version = "1.8.22"
ext.kotlin_version = "2.1.0"
repositories {
google()
mavenCentral()
Expand All @@ -22,7 +22,18 @@ allprojects {
}

apply plugin: "com.android.library"
apply plugin: "kotlin-android"

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

android {
if (project.android.hasProperty("namespace")) {
Expand All @@ -36,10 +47,6 @@ android {
targetCompatibility = JavaVersion.VERSION_1_8
}

kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8
}

sourceSets {
main.java.srcDirs += "src/main/kotlin"
test.java.srcDirs += "src/test/kotlin"
Expand Down Expand Up @@ -68,3 +75,19 @@ android {
}
}
}

// Configure the Kotlin JVM target. The compilerOptions DSL requires KGP 1.9+ or
// AGP 9 built-in Kotlin; older Flutter app templates ship KGP 1.8.x, which only
// supports the legacy kotlinOptions DSL.
def kotlinExt = project.extensions.findByName("kotlin")
if (kotlinExt?.hasProperty("compilerOptions")) {
kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_1_8
}
}
} else {
android.kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
Loading