Skip to content

Commit

Permalink
fix: Bundle assets in monorepo (#26940)
Browse files Browse the repository at this point in the history
Summary:
In monorepo environment, `metro` isn't able to resolve `react-native` because the path to it is hardcoded.

I've also added `packagingOptions` to RNTester to make Android builds work for me. Let me know if this is something that is only specific to my setup, and shouldn't be added.

## Changelog

[Android] [Fixed] - Fix `bundleReleaseJsAndAssets` in monorepo env
Pull Request resolved: #26940

Test Plan:
- [x] - Works in monorepo setup on MacOS
- [x] - Works with RNTester app

Differential Revision: D18323703

Pulled By: cpojer

fbshipit-source-id: b8eb15dfd8a32ae11fd862fc725af9cffea2cf96
  • Loading branch information
Esemesek authored and grabbou committed Nov 23, 2019
1 parent 95a5101 commit 51f74e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 0 additions & 1 deletion RNTester/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ plugins {
*/

project.ext.react = [
cliPath: "$rootDir/cli.js",
bundleAssetName: "RNTesterApp.android.bundle",
entryFile: file("../../js/RNTesterApp.android.js"),
root: "$rootDir",
Expand Down
26 changes: 17 additions & 9 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ afterEvaluate {
// Additional node and packager commandline arguments
def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"]
def extraPackagerArgs = config.extraPackagerArgs ?: []
def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx"

def execCommand = []

if (config.cliPath || config.nodeExecutableAndArgs) {
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
execCommand.addAll(["cmd", "/c", *nodeExecutableAndArgs, cliPath])
} else {
execCommand.addAll([*nodeExecutableAndArgs, cliPath])
}
} else {
execCommand.addAll([npx, "react-native"])
}

def enableHermes = enableHermesForVariant(variant)

Expand Down Expand Up @@ -126,15 +139,10 @@ afterEvaluate {
extraArgs.add(bundleConfig);
}

if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine("cmd", "/c", *nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
"--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)
} else {
commandLine(*nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
"--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)
}
commandLine(*execCommand, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
"--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)


if (enableHermes) {
doLast {
Expand Down

0 comments on commit 51f74e7

Please sign in to comment.