Skip to content
Browse files
fix: Android gradle config when bundling for release (#28415)
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
  • Loading branch information
vdmtrv authored and facebook-github-bot committed Mar 28, 2020
1 parent 602070f commit 0d1fb458ab8027dcfac5f2fa11e8c16d6853c59c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
@@ -65,6 +65,7 @@ plugins {

project.ext.react = [
cliPath: "$rootDir/cli.js",
bundleAssetName: "",
entryFile: file("../../js/"),
root: "$rootDir",
@@ -110,7 +110,8 @@ afterEvaluate {
execCommand.addAll([*nodeExecutableAndArgs, cliPath])
} else {
execCommand.addAll([npx, "react-native"])
throw new Exception("Missing cliPath or nodeExecutableAndArgs from build config. " +
"Please set project.ext.react.cliPath to the path of the react-native cli.js");

def enableHermes = enableHermesForVariant(variant)

0 comments on commit 0d1fb45

Please sign in to comment.