From 4f90933d1930cff96a3e99bd284d790d5232fa2b Mon Sep 17 00:00:00 2001 From: Jesse Katsumata Date: Mon, 23 Nov 2026 13:47:58 +0900 Subject: [PATCH] fix(android): compile the library's Kotlin sources under AGP 9 built-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 --- android/build.gradle | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 50e0cf53..becf9d8e 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -128,22 +128,31 @@ android { sourceSets { main { + def extraSrcDirs = [] if (isNewArchitectureEnabled()) { - java.srcDirs += [ + extraSrcDirs += [ "src/newarch", // This is needed to build Kotlin project with NewArch enabled "${project.buildDir}/generated/source/codegen/java" ] } else { - java.srcDirs += ["src/oldarch"] + extraSrcDirs += ["src/oldarch"] } // MenuViewManager if (getReactNativeMinorVersion() <= 75) { - java.srcDirs += "src/reactNativeVersionPatch/MenuViewManager/75" + extraSrcDirs += ["src/reactNativeVersionPatch/MenuViewManager/75"] } else { - java.srcDirs += "src/reactNativeVersionPatch/MenuViewManager/latest" + extraSrcDirs += ["src/reactNativeVersionPatch/MenuViewManager/latest"] } + + java.srcDirs += extraSrcDirs + // AGP 9's built-in Kotlin compiles .kt files only from the `kotlin` source + // directories. Directories added to `java.srcDirs` alone are skipped, and the + // build fails with "Unresolved reference 'MenuViewManager'". The Kotlin Gradle + // plugin (used when built-in Kotlin is off) already reads both, so listing the + // directories in each is safe on every setup. + kotlin.srcDirs += extraSrcDirs } } }