fix(android): skip explicit Kotlin plugin when AGP provides built-in Kotlin - #1966
Open
gabrieldonadel wants to merge 1 commit into
Open
fix(android): skip explicit Kotlin plugin when AGP provides built-in Kotlin#1966gabrieldonadel wants to merge 1 commit into
gabrieldonadel wants to merge 1 commit into
Conversation
…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. AGP 10 removes that opt-out, so built-in Kotlin is always active there and the explicit apply must never run.
gabrieldonadel
force-pushed
the
fix/agp9-built-in-kotlin
branch
from
September 2, 2026 21:01
d2f94d8 to
2078973
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Android Gradle Plugin 9 ships built-in Kotlin support and enables it by default, so AGP
applies the Kotlin plugin itself. When a library also applies
kotlin-androidexplicitly, thetwo collide and configuration fails before anything compiles:
The apply is unconditional in these files, so on an AGP 9 project they cannot be built
at all. There is no consumer-side workaround short of patching the file — setting
android.builtInKotlin=falseproject-wide just to build one dependency is not areasonable ask, and that escape hatch is removed in AGP 10.
Change
Keep the explicit apply, but skip it when AGP is already providing Kotlin:
Files changed:
packages/analytics-react-native/android/build.gradlepackages/plugin-session-replay-react-native/android/build.gradlepackages/session-replay-react-native/android/build.gradleWhy the condition has this shape
Both halves are load-bearing:
AGP nothing else applies the Kotlin plugin, so skipping would break the build in the
opposite direction.
android.builtInKotlindefaults to on in AGP 9, soonly an explicit
falsemeans "AGP is not providing Kotlin, apply it yourself". Thismirrors AGP's own default.
android.builtInKotlinfalsetruefalsecom.android.Version.ANDROID_GRADLE_PLUGIN_VERSIONrequires no new plugin resolution,and the apply already happens after
com.android.library, so AGP is on the classpath.What I verified, and what I did not
9.2.1 and Gradle 9.4.1:
:app:assembleDebugsucceeds both with-Pandroid.newDsl=true -Pandroid.builtInKotlin=trueand with both flags off. Sameguard, both configurations green.
Phases.CONVERSION.construction, since
shouldApplyKotlinPlugin()short-circuits totruethere — but aCI run is the real confirmation and I could not do that from outside.
Found while sweeping 157 popular React Native libraries for AGP 9 new-DSL compatibility.
34 failed with the new DSL enabled, and 29 of those failed on exactly this — it is the
most common blocker by a wide margin.
Note
Low Risk
Build-time Gradle plugin wiring only; AGP 8 behavior is unchanged and there is no runtime or application logic impact.
Overview
Fixes Gradle configuration failures on Android Gradle Plugin 9+ where these React Native Android libraries unconditionally applied
kotlin-androidwhile AGP already registers Kotlin, causing "Cannot add extension with name 'kotlin'" during configuration.Each affected
android/build.gradle(analytics-react-native,plugin-session-replay-react-native,session-replay-react-native) now applieskotlin-androidonly when AGP is not supplying Kotlin: always on AGP 8 and below, never on AGP 10+, and on AGP 9 only when theandroid.builtInKotlinproperty is explicitlyfalse(unset defaults to built-in Kotlin on, so the explicit apply is skipped).Reviewed by Cursor Bugbot for commit 2078973. Bugbot is set up for automated code reviews on this repo. Configure here.