Skip to content

Commit 05be144

Browse files
fix(android): skip explicit Kotlin plugin when AGP provides built-in Kotlin
AGP 9 enables built-in Kotlin by default and applies the Kotlin plugin itself. Applying it again fails configuration with "Cannot add extension with name 'kotlin'". Guard the explicit apply so it only runs when AGP is not providing Kotlin: AGP 8 and older, or AGP 9+ with android.builtInKotlin=false.
1 parent a523007 commit 05be144

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

‎android/build.gradle‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,24 @@ def isNewArchitectureEnabled() {
1818
}
1919

2020
apply plugin: 'com.android.library'
21-
apply plugin: 'org.jetbrains.kotlin.android'
21+
// Android Gradle Plugin 9 ships built-in Kotlin support and applies the Kotlin
22+
// plugin itself. Applying it a second time fails the configuration phase with
23+
// "Cannot add extension with name 'kotlin'". Apply it only when AGP is not
24+
// providing Kotlin: AGP 8 and older, or AGP 9+ with android.builtInKotlin=false.
25+
def shouldApplyKotlinPlugin() {
26+
def agpMajor = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')[0].toInteger()
27+
if (agpMajor <= 8) {
28+
return true
29+
}
30+
def propertyVal = providers.gradleProperty("android.builtInKotlin").orNull
31+
def builtInKotlinEnabled = propertyVal != null ? propertyVal.toBoolean() : true
32+
return !builtInKotlinEnabled
33+
}
34+
35+
if (shouldApplyKotlinPlugin()) {
36+
apply plugin: 'org.jetbrains.kotlin.android'
37+
}
38+
2239
if (isNewArchitectureEnabled()) {
2340
apply plugin: "com.facebook.react"
2441
}

0 commit comments

Comments
 (0)