Skip to content

fix(android): compile the library's Kotlin sources under AGP 9 built-in Kotlin - #1264

Merged
Naturalclar merged 1 commit into
masterfrom
fix/android-builtin-kotlin-srcdirs
Nov 23, 2026
Merged

Naturalclar merged 1 commit into
masterfrom
fix/android-builtin-kotlin-srcdirs

Conversation

@Naturalclar

Copy link
Copy Markdown
Member

Problem

android/build.gradle adds src/newarch and the reactNativeVersionPatch/MenuViewManager/* folder to java.srcDirs only. Under AGP 9's built-in Kotlin, .kt files are compiled only from the kotlin source directories, so those folders are skipped and the library doesn't compile:

e: .../com/reactnativemenu/MenuPackage.kt:18:30 Unresolved reference 'MenuViewManager'.
> Task :react-native-menu_menu:compileDebugKotlin FAILED

I found this while investigating the React Native 0.88 upgrade (#1249). RN 0.88 needs Gradle 9.4.1 / AGP 9.2.1. The RN 0.88 app template opts out with android.builtInKotlin=false, so only apps that turn built-in Kotlin on hit this today. AGP 10 removes the opt-out.

Change (android/build.gradle only)

Collect the extra source directories once, then add them to both java.srcDirs and kotlin.srcDirs. The Kotlin Gradle plugin, which is used when built-in Kotlin is off, already reads both, so listing a directory in each is safe there too. Which directories are selected doesn't change.

Verification (local, example app assembleDebug)

Setup Before After
RN 0.81 / AGP 8 / Kotlin Gradle plugin (current master) ✅ ✅ (no duplicate-declaration errors)
RN 0.88 / AGP 9.2.1 / built-in Kotlin on ❌ library compileDebugKotlin fails as above ✅ library compiles ¹
RN 0.88 / AGP 9.2.1 / template settings (builtInKotlin=false, newDsl=false) ✅ ✅

¹ The example's :app still fails in that setup, inside react-native-test-app's own MainActivity.kt. rnta has the same java.srcDirs pattern, so that's outside this library.

CI builds RN 0.81, so it covers only the first row.

🤖 Generated with Claude Code

…in Kotlin

android/build.gradle adds src/newarch and the reactNativeVersionPatch
folder to `java.srcDirs` only. Under AGP 9's built-in Kotlin, .kt files
are compiled only from the `kotlin` source directories, so those folders
are skipped and the library fails to compile:

  MenuPackage.kt:18:30 Unresolved reference 'MenuViewManager'.

Collect the extra directories once, then add them to both `java.srcDirs`
and `kotlin.srcDirs`. The Kotlin Gradle plugin, which is used when
built-in Kotlin is off, already reads both, so this is safe there too.

The React Native 0.88 template opts out with android.builtInKotlin=false,
so only apps that enable built-in Kotlin hit this today. AGP 10 removes
that opt-out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Naturalclar
Naturalclar merged commit d8b0a27 into master Nov 23, 2026
6 checks passed
@Naturalclar
Naturalclar deleted the fix/android-builtin-kotlin-srcdirs branch November 23, 2026 04:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant