File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,10 +23,14 @@ allprojects {
2323
2424apply 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.
2830def 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 {
You can’t perform that action at this time.
0 commit comments