Skip to content

Commit e9fa6f7

Browse files
authored
fix(android): fix 'cannot find react-native' error on 0.80 (#2433)
1 parent bcb8087 commit e9fa6f7

File tree

3 files changed

+48
-48
lines changed

3 files changed

+48
-48
lines changed

example/android/build.gradle

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ buildscript {
2424

2525
allprojects {
2626
repositories {
27-
maven {
28-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
29-
url({
30-
def searchDir = rootDir.toPath()
31-
do {
32-
def p = searchDir.resolve("node_modules/react-native/android")
33-
if (p.toFile().exists()) {
34-
return p.toRealPath().toString()
27+
{
28+
def searchDir = rootDir.toPath()
29+
do {
30+
def p = searchDir.resolve("node_modules/react-native/android")
31+
if (p.toFile().exists()) {
32+
maven {
33+
url(p.toRealPath().toString())
3534
}
36-
} while (searchDir = searchDir.getParent())
37-
throw new GradleException("Could not find `react-native`");
38-
}())
39-
}
35+
break
36+
}
37+
} while (searchDir = searchDir.getParent())
38+
// As of 0.80, React Native is no longer installed from npm
39+
}()
4040
mavenCentral()
4141
google()
4242
}

scripts/template.mjs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,19 @@ export function buildGradle() {
7575
// https://github.com/facebook/react-native/commit/51a48d2e2c64a18012692b063368e369cd8ff797
7676
"allprojects {",
7777
" repositories {",
78-
" maven {",
79-
" // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm",
80-
" url({",
81-
" def searchDir = rootDir.toPath()",
82-
" do {",
83-
' def p = searchDir.resolve("node_modules/react-native/android")',
84-
" if (p.toFile().exists()) {",
85-
" return p.toRealPath().toString()",
78+
" {",
79+
" def searchDir = rootDir.toPath()",
80+
" do {",
81+
' def p = searchDir.resolve("node_modules/react-native/android")',
82+
" if (p.toFile().exists()) {",
83+
" maven {",
84+
" url(p.toRealPath().toString())",
8685
" }",
87-
" } while (searchDir = searchDir.getParent())",
88-
' throw new GradleException("Could not find `react-native`");',
89-
" }())",
90-
" }",
86+
" break",
87+
" }",
88+
" } while (searchDir = searchDir.getParent())",
89+
" // As of 0.80, React Native is no longer installed from npm",
90+
" }()",
9191
" mavenCentral()",
9292
" google()",
9393
" }",

test/configure/gatherConfig.test.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ describe("gatherConfig()", () => {
7979
"",
8080
"allprojects {",
8181
" repositories {",
82-
" maven {",
83-
" // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm",
84-
" url({",
85-
" def searchDir = rootDir.toPath()",
86-
" do {",
87-
' def p = searchDir.resolve("node_modules/react-native/android")',
88-
" if (p.toFile().exists()) {",
89-
" return p.toRealPath().toString()",
82+
" {",
83+
" def searchDir = rootDir.toPath()",
84+
" do {",
85+
' def p = searchDir.resolve("node_modules/react-native/android")',
86+
" if (p.toFile().exists()) {",
87+
" maven {",
88+
" url(p.toRealPath().toString())",
9089
" }",
91-
" } while (searchDir = searchDir.getParent())",
92-
' throw new GradleException("Could not find `react-native`");',
93-
" }())",
94-
" }",
90+
" break",
91+
" }",
92+
" } while (searchDir = searchDir.getParent())",
93+
" // As of 0.80, React Native is no longer installed from npm",
94+
" }()",
9595
" mavenCentral()",
9696
" google()",
9797
" }",
@@ -427,19 +427,19 @@ describe("gatherConfig()", () => {
427427
"",
428428
"allprojects {",
429429
" repositories {",
430-
" maven {",
431-
" // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm",
432-
" url({",
433-
" def searchDir = rootDir.toPath()",
434-
" do {",
435-
' def p = searchDir.resolve("node_modules/react-native/android")',
436-
" if (p.toFile().exists()) {",
437-
" return p.toRealPath().toString()",
430+
" {",
431+
" def searchDir = rootDir.toPath()",
432+
" do {",
433+
' def p = searchDir.resolve("node_modules/react-native/android")',
434+
" if (p.toFile().exists()) {",
435+
" maven {",
436+
" url(p.toRealPath().toString())",
438437
" }",
439-
" } while (searchDir = searchDir.getParent())",
440-
' throw new GradleException("Could not find `react-native`");',
441-
" }())",
442-
" }",
438+
" break",
439+
" }",
440+
" } while (searchDir = searchDir.getParent())",
441+
" // As of 0.80, React Native is no longer installed from npm",
442+
" }()",
443443
" mavenCentral()",
444444
" google()",
445445
" }",

0 commit comments

Comments
 (0)