Skip to content

Commit 0d1fb45

Browse files
vdmtrvfacebook-github-bot
authored andcommitted
fix: Android gradle config when bundling for release (#28415)
Summary: This fix aims to address the issue when bundling an Android app for release and getting the error exhibited in #28002 which I also encountered myself. The config was changed sometime in November 2019 (as part of #26940, commit a3b0804) to be very opinionated when it comes to the use of `npx` which Gradle itself cannot find anyway (I have `npx` installed globally and it didn't pick it up). Another issue that the use of `npx` creates is that Gradle should only ever use the currently installed react-native cli rather than a (possibly) higher version which may not always have backward compatibility. The proposed change simply throws a more descriptive error rather than defaulting to a tool which may or may not exist on the machine, be it CI or a development environment. I've also modified the RNTester app to reflect the correct config implementation relative to the RNTester app itself. In real projects, the config inside `android/app/build.gradle` should look similar to the following snippet: ``` project.ext.react = [ cliPath: "$rootDir/../node_modules/react-native/cli.js", entryFile: "index.js" ]; ``` ## Changelog [Android] [Fixed] - Gradle release config Pull Request resolved: #28415 Test Plan: - [x] Successfully bundled an Android release build with correct config - [x] Works with RNTester app Reviewed By: mdvacca Differential Revision: D20714372 Pulled By: hramos fbshipit-source-id: 4d66139249c6f840582a71a48c64e6a6595f7af0
1 parent 602070f commit 0d1fb45

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

RNTester/android/app/build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ plugins {
6565
*/
6666

6767
project.ext.react = [
68+
cliPath: "$rootDir/cli.js",
6869
bundleAssetName: "RNTesterApp.android.bundle",
6970
entryFile: file("../../js/RNTesterApp.android.js"),
7071
root: "$rootDir",

react.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ afterEvaluate {
110110
execCommand.addAll([*nodeExecutableAndArgs, cliPath])
111111
}
112112
} else {
113-
execCommand.addAll([npx, "react-native"])
113+
throw new Exception("Missing cliPath or nodeExecutableAndArgs from build config. " +
114+
"Please set project.ext.react.cliPath to the path of the react-native cli.js");
114115
}
115116

116117
def enableHermes = enableHermesForVariant(variant)

0 commit comments

Comments
 (0)