Skip to content

Instantly share code, notes, and snippets.

@ashwin1014
Created February 28, 2024 06:13
Show Gist options
  • Save ashwin1014/893730aa9b35be79f09807f94cabd82d to your computer and use it in GitHub Desktop.
Save ashwin1014/893730aa9b35be79f09807f94cabd82d to your computer and use it in GitHub Desktop.
react-native android dynamic node_modules discovery when hoisted in mono-repo
When using a react-native inside a mono-repo, builds dont work when node_modules are hoisted. To fix this, we make a few changes in gradle files.
"apps/mobile-app/android/app/build.gradle" -> update with below changes
reactNativeDir = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
codegenDir = new File(["node", "--print", "require.resolve('@react-native/codegen/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsoluteFile()
cliFile = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim(), "../cli.js").getAbsoluteFile()
hermesCommand = new File(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim()).getParentFile().getAbsolutePath() + "/sdks/hermesc/%OS-BIN%/hermesc"
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle")
applyNativeModulesAppBuildGradle(project)
"apps/mobile-app/android/settings.gradle" -> update with below changes
apply from: new File(["node", "--print", "require.resolve('@react-native-community/cli-platform-android/package.json')"].execute(null, rootDir).text.trim(), "../native_modules.gradle")
applyNativeModulesSettingsGradle(settings)
includeBuild(new File(["node", "--print", "require.resolve('@react-native/gradle-plugin/package.json')"].execute(null, rootDir).text.trim()).getParentFile())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment