From ce51b6249449361ee50b8c99a427c28af7ab3531 Mon Sep 17 00:00:00 2001 From: Vitaly Iegorov Date: Wed, 15 Sep 2021 10:30:34 -0700 Subject: [PATCH] Fixed Android cliPath Gradle configuration option for build.gradle (#31839) Summary: When using monorepo with react-native you need to provide `android/app/build.gradle` following params(`cliPath`): ``` project.ext.react = [ root: "../../../../", cliPath: "../../../../node_modules/react-native/cli.js", entryFile: "...", hermesCommand: "../../../../node_modules/hermes-engine/%OS-BIN%/hermesc" ] ``` With latest react-native `0.64.2` version you will get: ``` * What went wrong: Execution failed for task ':app:bundleReleaseJsAndAssets'. > Process 'command 'node'' finished with non-zero exit value 1 ``` Debugging this issue showed that providing `cliPath` options ends up building wrong path to cli: ``` > Task :app:bundleReleaseJsAndAssets FAILED node:internal/modules/cjs/loader:944 throw err; ^ Error: Cannot find module '/node_modules/react-native/cli.js' at Function.Module._resolveFilename (node:internal/modules/cjs/loader:941:15) at Function.Module._load (node:internal/modules/cjs/loader:774:27) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12) at node:internal/main/run_main_module:17:47 { code: 'MODULE_NOT_FOUND', requireStack: [] } ``` Changed `react.gradle` for proper File creation for `cliPath` to support this configuration option. ## Changelog [Android] [Fixed] - Changed `react.gradle` `detectCliPath` function logic for `cliPath` case Pull Request resolved: https://github.com/facebook/react-native/pull/31839 Test Plan: Run `./gradlew assembleRelease` or `./gradlew assembleDebug` Reviewed By: yungsters Differential Revision: D30877674 Pulled By: sshic fbshipit-source-id: 26b75f8d29bf26b01630dde576b9052d0b94d89e --- react.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/react.gradle b/react.gradle index ff46476cacc7a6..867a06e14bec22 100644 --- a/react.gradle +++ b/react.gradle @@ -26,7 +26,7 @@ def detectEntryFile(config) { */ def detectCliPath(config) { if (config.cliPath) { - return config.cliPath + return "${projectDir}/${config.cliPath}" } if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) { return "${projectDir}/../../node_modules/react-native/cli.js"