From c5ae0c820a571141a43de980cb011d232fc2268f Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Tue, 17 Feb 2026 10:29:47 -0800 Subject: [PATCH] fix(react-native): resolve included-build gradle.properties from parent build in monorepos (#55569) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: _Disclaimer: The code was generated using GPT-5.3 Codex. I have read it, and it looks fine, but I'm no android expert. I made sure with logging that everything worked._ React Native’s included build was reading only ../../android/gradle.properties, which breaks in monorepos where Android apps live under packages/*/android. This updates settings.gradle.kts to resolve gradle.properties from the parent Gradle start parameters (projectDir/currentDir) first, with the old relative path kept as a backward-compatible fallback. This ensures hermesV1Enabled and react.hermesV1Enabled are propagated reliably across composite builds. ## Changelog: [ANDROID] [FIXED] Fix included-build `gradle.properties` resolution for monorepos by reading from parent Gradle start parameters (`projectDir`/`currentDir`) before falling back to `../../android/gradle.properties`, so `hermesV1Enabled` can be inherited correctly. Pull Request resolved: https://github.com/facebook/react-native/pull/55569 Test Plan: I've tested manually with expo sdk 55 in our monorepo. Ideally we'll want this in 83, so that expo 55 can use hermes V1 in monorepos Reviewed By: cipolleschi Differential Revision: D93478206 Pulled By: cortinico fbshipit-source-id: ebb8b4dd555b86b6cba57d9b197557a6aab1887f --- packages/react-native/settings.gradle.kts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/react-native/settings.gradle.kts b/packages/react-native/settings.gradle.kts index 3a7ab35f3af..62527f0149f 100644 --- a/packages/react-native/settings.gradle.kts +++ b/packages/react-native/settings.gradle.kts @@ -47,8 +47,28 @@ buildscript { val properties = java.util.Properties() val propertiesToInherit = listOf("hermesV1Enabled", "react.hermesV1Enabled") + // We cannot assume that the node_modules are next to the android project, for example + // in monorepos, they might get hoisted. + // In a composite build, this included build can access the invoking (consumer) build + // via `gradle.parent`. We use its StartParameter to locate the app's `gradle.properties`: + // - `projectDir/gradle.properties` when Gradle is run with `-p ` + // - `currentDir/gradle.properties` when run from the app android folder + // If neither exists, we keep the legacy RN fallback path below. + + val parentGradle = gradle.parent + val parentProjectDir = parentGradle?.startParameter?.projectDir + val parentCurrentDir = parentGradle?.startParameter?.currentDir + val gradlePropertiesCandidates = + listOfNotNull( + parentProjectDir?.resolve("gradle.properties"), + parentCurrentDir?.resolve("gradle.properties"), + // Backward-compatible fallback for classic RN app layouts. + file("../../android/gradle.properties"), + ) + try { - file("../../android/gradle.properties").inputStream().use { properties.load(it) } + val propertiesFile = gradlePropertiesCandidates.firstOrNull { it.exists() } + propertiesFile?.inputStream()?.use { properties.load(it) } gradle.rootProject { propertiesToInherit.forEach { property ->