Skip to content

Commit

Permalink
fix: resolve react native dir in monorepo in android build
Browse files Browse the repository at this point in the history
  • Loading branch information
rolud committed Nov 15, 2024
1 parent 7d02596 commit f541c87
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions android/react-native-helpers.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,17 @@ def safeAppExtGet(prop, fallback) {
}

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

// monorepo workaround
// react-native can be hoisted or in project's own node_modules
def reactNativeFromProjectNodeModules = file("${rootProject.projectDir}/../node_modules/react-native")
if (reactNativeFromProjectNodeModules.exists()) {
return reactNativeFromProjectNodeModules
}

def reactNativeFromNodeModules = file("${projectDir}/../../react-native")
if (reactNativeFromNodeModules.exists()) {
return reactNativeFromNodeModules
// Fallback to node resolver for custom directory structures like monorepos.
def reactNativePackage = file(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim())
if(reactNativePackage.exists()) {
return reactNativePackage.parentFile
}

throw new GradleException(
Expand Down

0 comments on commit f541c87

Please sign in to comment.