Repository navigation
fix(android): skip explicit Kotlin plugin when AGP registers the kotlin extension - #377
gabrieldonadel wants to merge 3 commits 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.
|
Thanks Gabriel! The guard is correct and changes nothing on AGP 8. I pushed a small commit shortening the comment to one line. We tried it with AGP 9.1.0, Gradle 9.3.1 and RN 0.80.3. With built-in Kotlin on, the guard gets past configuration, but RN 0.87 ships AGP 9 with built-in Kotlin and the new DSL off by default, so two questions:
Happy to add those here or in a follow-up. |
Built-in Kotlin only compiles kotlin.srcDirs, so the Kotlin sources that were reachable only through java.srcDirs (src/new/java or src/legacy/java, and the Nitrogen-generated android/kotlin dir added by rive+autolinking.gradle) failed with unresolved references.
|
Thanks for testing it properly, and for the comment fix. You're right, and I owe you a correction. 1. What I tested. The "verified end to end" section in the description doesn't hold for Rive. This PR came out of a sweep on Expo SDK 58 / RN 0.87.0, AGP 9.2.1, Gradle 9.4.1. In that sweep, Rive never got as far as compiling: with the flags on it hit the I've now reproduced it properly: same setup, 2. The other two pieces.
Verified on the setup above with cac8165. Nitro-modules still needs margelo/nitro#1579 and its own
So for a full built-in-Kotlin build on RN 0.87, Rive also needs a Nitro release that includes #1579 plus |
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 all 2 modules below, 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.gradlerive-debug-utils/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 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
@rive-app/react-nativehere.The same guard shape was accepted in
RevenueCat/react-native-purchases#1934,
at that maintainer's suggestion.