Skip to content

Commit

Permalink
feat: add monorepo support for Android builds (#2352)
Browse files Browse the repository at this point in the history
## Description

Based on:
#2337 by
@morganick.
Please see the original PR and its description for details.

See:
#2337 (review)
for discussion why new PR has been created.

## Changes

- **Using node resolver to find react native package for better monorepo
support**
- **Using rootDir instead of projectDir**
- **Change the order of path lookup**

## Test code and steps to reproduce

I've tested it using our both example apps and additionally I've created
fresh RN app
and tested the Android build there.


## Checklist

- [x] Ensured that CI passes

---------

Co-authored-by: Nick Morgan <morganick@users.noreply.github.com>
  • Loading branch information
kkafar and morganick authored Sep 25, 2024
1 parent 75c15c1 commit 408112a
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,26 @@ android {
repositories {
maven {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
// Matches the RN Hello World template

// First look for the standard location of react-native, as in RN Hello World template
// https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21
url "$projectDir/../node_modules/react-native/android"
// TODO(kkafar): Note, that in latest template app https://github.com/react-native-community/template/blob/0f4745b7a9d84232aeedec2def8d75ab9b050d11/template/android/build.gradle
// this is not specified at all.
File standardRnAndroidDirLocation = file("$rootDir/../node_modules/react-native/android")
if (standardRnAndroidDirLocation.exists()) {
url standardRnAndroidDirLocation
} else {
// We're in non standard setup - try to use node resolver to locate the react-native package.
File reactNativePackage = file(["node", "--print", "require.resolve('react-native/package.json')"].execute(null, rootDir).text.trim())
def rnAndroidDirLocation = "$reactNativePackage.parentFile/android"
if (reactNativePackage.exists()) {
url rnAndroidDirLocation
} else {
println "[RNScreens] Failed to resolve react-native directory. Attempted locations: ${standardRnAndroidDirLocation}, ${rnAndroidDirLocation}"
}
}
}

mavenCentral()
mavenLocal()
google()
Expand Down

0 comments on commit 408112a

Please sign in to comment.