Skip to content

Commit 7814ae3

Browse files
authored
fix(Android): Find react-native using node module resolution (#481)
1 parent 970eaa5 commit 7814ae3

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

android/build.gradle

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
import java.nio.file.Paths
2+
3+
def resolveModulePath(packageName) {
4+
def basePath = rootDir.toPath().normalize()
5+
6+
// Node's module resolution algorithm searches up to the root directory,
7+
// after which the base path will be null
8+
while (basePath) {
9+
def candidatePath = Paths.get(basePath.toString(), 'node_modules', packageName)
10+
if (candidatePath.toFile().exists()) {
11+
return candidatePath.toString()
12+
}
13+
14+
basePath = basePath.getParent()
15+
}
16+
17+
return null
18+
}
19+
120
def safeExtGet(prop, fallback) {
221
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
322
}
@@ -53,7 +72,7 @@ repositories {
5372
mavenLocal()
5473
maven {
5574
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
56-
url "$rootDir/../node_modules/react-native/android"
75+
url "${resolveModulePath("react-native")}/android"
5776
}
5877
google()
5978
jcenter()

0 commit comments

Comments
 (0)