fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension - #159
Open
gabrieldonadel wants to merge 1 commit into
Open
fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension#159gabrieldonadel wants to merge 1 commit into
gabrieldonadel wants to merge 1 commit into
Conversation
…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.
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 registers the
kotlinextension itself. When a library also applieskotlin-androidexplicitly, 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=falseproject-wide just to build one dependency is not areasonable ask, and that escape hatch is removed in AGP 10.
Change
Apply the plugin only when nothing has registered the
kotlinextension yet:Files changed:
android/build.gradleThis 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.builtInKotlinopt-out isremoved — without a special case.
android.builtInKotlinkotlinextensionfalsetruefalseThe 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:assembleDebugsucceeds both with-Pandroid.newDsl=true -Pandroid.builtInKotlin=trueand with both flags off.the flags off,
compileDebugKotlinruns from the explicitly applied plugin; withthem on the build completes without it.
Phases.CONVERSIONsyntax check.Where this came from
A sweep of 500 popular React Native libraries against the AGP 9 defaults. 152 failed
with the new DSL enabled, and 144 of those failed on exactly this collision — by
far the most common blocker. Affects
skyflow-react-nativehere.The same guard shape was accepted in
RevenueCat/react-native-purchases#1934,
at that maintainer's suggestion.