From dd9015f33846905610224db2b5267cb0860a3c8e Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Mon, 31 Mar 2025 11:55:16 +0200 Subject: [PATCH 1/2] fix(android): fix 'cannot find `react-native`' error on 0.80 --- example/android/build.gradle | 24 +++++++-------- scripts/template.mjs | 24 +++++++-------- test/configure/gatherConfig.test.ts | 48 ++++++++++++++--------------- 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index d8bcc3aeb..9008e1cec 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -24,19 +24,19 @@ buildscript { allprojects { repositories { - maven { - // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm - url({ - def searchDir = rootDir.toPath() - do { - def p = searchDir.resolve("node_modules/react-native/android") - if (p.toFile().exists()) { - return p.toRealPath().toString() + { + def searchDir = rootDir.toPath() + do { + def p = searchDir.resolve("node_modules/react-native/android") + if (p.toFile().exists()) { + maven { + url(p.toRealPath().toString()) } - } while (searchDir = searchDir.getParent()) - throw new GradleException("Could not find `react-native`"); - }()) - } + break + } + } while (searchDir = searchDir.getParent()) + // As of 0.79, React Native is no longer installed from npm + }() mavenCentral() google() } diff --git a/scripts/template.mjs b/scripts/template.mjs index 854307922..21d4784d2 100644 --- a/scripts/template.mjs +++ b/scripts/template.mjs @@ -75,19 +75,19 @@ export function buildGradle() { // https://github.com/facebook/react-native/commit/51a48d2e2c64a18012692b063368e369cd8ff797 "allprojects {", " repositories {", - " maven {", - " // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm", - " url({", - " def searchDir = rootDir.toPath()", - " do {", - ' def p = searchDir.resolve("node_modules/react-native/android")', - " if (p.toFile().exists()) {", - " return p.toRealPath().toString()", + " {", + " def searchDir = rootDir.toPath()", + " do {", + ' def p = searchDir.resolve("node_modules/react-native/android")', + " if (p.toFile().exists()) {", + " maven {", + " url(p.toRealPath().toString())", " }", - " } while (searchDir = searchDir.getParent())", - ' throw new GradleException("Could not find `react-native`");', - " }())", - " }", + " break", + " }", + " } while (searchDir = searchDir.getParent())", + " // As of 0.79, React Native is no longer installed from npm", + " }()", " mavenCentral()", " google()", " }", diff --git a/test/configure/gatherConfig.test.ts b/test/configure/gatherConfig.test.ts index 1ac7a484c..d7728a634 100644 --- a/test/configure/gatherConfig.test.ts +++ b/test/configure/gatherConfig.test.ts @@ -79,19 +79,19 @@ describe("gatherConfig()", () => { "", "allprojects {", " repositories {", - " maven {", - " // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm", - " url({", - " def searchDir = rootDir.toPath()", - " do {", - ' def p = searchDir.resolve("node_modules/react-native/android")', - " if (p.toFile().exists()) {", - " return p.toRealPath().toString()", + " {", + " def searchDir = rootDir.toPath()", + " do {", + ' def p = searchDir.resolve("node_modules/react-native/android")', + " if (p.toFile().exists()) {", + " maven {", + " url(p.toRealPath().toString())", " }", - " } while (searchDir = searchDir.getParent())", - ' throw new GradleException("Could not find `react-native`");', - " }())", - " }", + " break", + " }", + " } while (searchDir = searchDir.getParent())", + " // As of 0.79, React Native is no longer installed from npm", + " }()", " mavenCentral()", " google()", " }", @@ -427,19 +427,19 @@ describe("gatherConfig()", () => { "", "allprojects {", " repositories {", - " maven {", - " // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm", - " url({", - " def searchDir = rootDir.toPath()", - " do {", - ' def p = searchDir.resolve("node_modules/react-native/android")', - " if (p.toFile().exists()) {", - " return p.toRealPath().toString()", + " {", + " def searchDir = rootDir.toPath()", + " do {", + ' def p = searchDir.resolve("node_modules/react-native/android")', + " if (p.toFile().exists()) {", + " maven {", + " url(p.toRealPath().toString())", " }", - " } while (searchDir = searchDir.getParent())", - ' throw new GradleException("Could not find `react-native`");', - " }())", - " }", + " break", + " }", + " } while (searchDir = searchDir.getParent())", + " // As of 0.79, React Native is no longer installed from npm", + " }()", " mavenCentral()", " google()", " }", From 62e657bfe61ffe2d7b70deeb5c79bafb1bf15528 Mon Sep 17 00:00:00 2001 From: Tommy Nguyen <4123478+tido64@users.noreply.github.com> Date: Mon, 31 Mar 2025 15:15:33 +0200 Subject: [PATCH 2/2] 0.80, not 0.79 --- example/android/build.gradle | 2 +- scripts/template.mjs | 2 +- test/configure/gatherConfig.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/android/build.gradle b/example/android/build.gradle index 9008e1cec..6b403e9d7 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -35,7 +35,7 @@ allprojects { break } } while (searchDir = searchDir.getParent()) - // As of 0.79, React Native is no longer installed from npm + // As of 0.80, React Native is no longer installed from npm }() mavenCentral() google() diff --git a/scripts/template.mjs b/scripts/template.mjs index 21d4784d2..5700733d1 100644 --- a/scripts/template.mjs +++ b/scripts/template.mjs @@ -86,7 +86,7 @@ export function buildGradle() { " break", " }", " } while (searchDir = searchDir.getParent())", - " // As of 0.79, React Native is no longer installed from npm", + " // As of 0.80, React Native is no longer installed from npm", " }()", " mavenCentral()", " google()", diff --git a/test/configure/gatherConfig.test.ts b/test/configure/gatherConfig.test.ts index d7728a634..1f136e74d 100644 --- a/test/configure/gatherConfig.test.ts +++ b/test/configure/gatherConfig.test.ts @@ -90,7 +90,7 @@ describe("gatherConfig()", () => { " break", " }", " } while (searchDir = searchDir.getParent())", - " // As of 0.79, React Native is no longer installed from npm", + " // As of 0.80, React Native is no longer installed from npm", " }()", " mavenCentral()", " google()", @@ -438,7 +438,7 @@ describe("gatherConfig()", () => { " break", " }", " } while (searchDir = searchDir.getParent())", - " // As of 0.79, React Native is no longer installed from npm", + " // As of 0.80, React Native is no longer installed from npm", " }()", " mavenCentral()", " google()",