Skip to content

Commit 9be943b

Browse files
authored
Merge pull request #485 from qeepcologne/main
fix broken agp9 compat
2 parents 195fed6 + 722d35a commit 9be943b

1 file changed

Lines changed: 15 additions & 5 deletions

File tree

android/build.gradle

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,14 @@ allprojects {
2323

2424
apply plugin: "com.android.library"
2525

26-
// AGP 9 enables built-in Kotlin support by default (android.builtInKotlin=true),
27-
// which conflicts with applying kotlin-android explicitly. Guard for AGP < 9.
26+
// AGP 9 ships built-in Kotlin support (`android.builtInKotlin=true` by default). Applying
27+
// `kotlin-android` on top of that conflicts, so skip it in that case. Users running AGP 9 with
28+
// `android.builtInKotlin=false` still need `kotlin-android` applied — otherwise there's no
29+
// Kotlin plugin at all and the Kotlin DSL below has nothing to bind to.
2830
def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.split('\\.')[0].toInteger()
29-
if (agpMajor < 9) {
31+
def builtInKotlinEnabled = (project.findProperty("android.builtInKotlin") ?: "true").toString().toBoolean()
32+
def useBuiltInKotlin = (agpMajor >= 9 && builtInKotlinEnabled)
33+
if (!useBuiltInKotlin) {
3034
apply plugin: "kotlin-android"
3135
}
3236

@@ -40,8 +44,14 @@ android {
4044
targetCompatibility = JavaVersion.VERSION_17
4145
}
4246

43-
kotlinOptions {
44-
jvmTarget = "17"
47+
// Built-in Kotlin defaults `kotlin.compilerOptions.jvmTarget` to
48+
// `android.compileOptions.targetCompatibility` (set above), so no explicit
49+
// configuration is needed in that mode. The legacy `kotlinOptions` DSL is
50+
// only available when `kotlin-android` is applied.
51+
if (!useBuiltInKotlin) {
52+
kotlinOptions {
53+
jvmTarget = "17"
54+
}
4555
}
4656

4757
sourceSets {

0 commit comments

Comments
 (0)