Skip to content

Commit f541c87

Browse files
committed
fix: resolve react native dir in monorepo in android build
1 parent 7d02596 commit f541c87

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

android/react-native-helpers.gradle

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@ def safeAppExtGet(prop, fallback) {
44
}
55

66
// Let's detect react-native's directory, it will be used to determine RN's version
7-
// https://github.com/software-mansion/react-native-reanimated/blob/cda4627c3337c33674f05f755b7485165c6caca9/android/build.gradle#L88
7+
// https://github.com/software-mansion/react-native-reanimated/blob/36c291a15880c78a94dd125c51484630546ceb7c/packages/react-native-reanimated/android/build.gradle#L73
88
def resolveReactNativeDirectory() {
99
def reactNativeLocation = safeAppExtGet("REACT_NATIVE_NODE_MODULES_DIR", null)
1010
if (reactNativeLocation != null) {
1111
return file(reactNativeLocation)
1212
}
1313

14-
// monorepo workaround
15-
// react-native can be hoisted or in project's own node_modules
16-
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
17-
if (reactNativeFromProjectNodeModules.exists()) {
18-
return reactNativeFromProjectNodeModules
19-
}
20-
21-
def reactNativeFromNodeModules = file("${projectDir}/../../react-native")
22-
if (reactNativeFromNodeModules.exists()) {
23-
return reactNativeFromNodeModules
14+
// Fallback to node resolver for custom directory structures like monorepos.
15+
def reactNativePackage = file(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim())
16+
if(reactNativePackage.exists()) {
17+
return reactNativePackage.parentFile
2418
}
2519

2620
throw new GradleException(

0 commit comments

Comments
 (0)