| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…in extension AGP 9 ships built-in Kotlin support and registers the kotlin extension itself. Applying the Kotlin plugin again fails configuration with "Cannot add extension with name 'kotlin'". Check for the extension directly, which needs no AGP version table and covers AGP 10, where the android.builtInKotlin opt-out is removed.
| Back | FazBrowse Home | New Git URL |
Problem
Android Gradle Plugin 9 ships built-in Kotlin support and enables it by default, so
AGP registers the kotlin extension itself. When a library also applies kotlin-android
explicitly, the two collide and configuration fails before anything compiles. AGP
words it two ways, both the same problem:
The apply is unconditional in this module, so on an AGP 9 project this cannot be built
at all. There is no consumer-side workaround short of patching the file — setting
android.builtInKotlin=false project-wide just to build one dependency is not a
reasonable ask, and that escape hatch is removed in AGP 10.
Change
Apply the plugin only when nothing has registered the kotlin extension yet:
Files changed:
This tests the condition that actually fails, so there is no AGP version table to
keep in sync, and it covers AGP 10 — where the android.builtInKotlin opt-out is
removed — without a special case.
The guard sits after apply plugin: 'com.android.library' in every file it touches,
so AGP has already registered its extensions by the time it runs. I checked that
ordering per file rather than assuming it.
What I verified, and what I did not
9.2.1 and Gradle 9.4.1: :app:assembleDebug succeeds both with
-Pandroid.newDsl=true -Pandroid.builtInKotlin=true and with both flags off.
the flags off, compileDebugKotlin runs from the explicitly applied plugin; with
them on the build completes without it.
Where this came from
A sweep of 1000 popular React Native libraries against the AGP 9 defaults. 281 failed
with the new DSL enabled, and 269 of those failed on exactly this collision — by
far the most common blocker. Affects @extole/react-native-sdk here.
The same guard shape was accepted in
RevenueCat/react-native-purchases#1934,
at that maintainer's suggestion.