Android: allow app/build.gradle to specify additional packager arguments

Summary:
If for instance you're using a custom transformer, having this hook will let you specify it without forking all of react.gradle

**Test plan:** Specified some additional packager args in my app's `android/app/build.gradle`:
```groovy
project.ext.react = [
  bundleInDebug: true,
  extraPackagerArgs: ["--transformer", "path/to/my/transformer.js"]
]
```
and ensured they show up when gradle invokes the bundler.
Closes https://github.com/facebook/react-native/pull/7858

Differential Revision: D3382996

Pulled By: mkonicek

fbshipit-source-id: 437b2e6c902931d45b9d2f7ec97c833ba0cd3217
This commit is contained in:
Philipp von Weitershausen 2016-06-02 17:27:24 -07:00 committed by Facebook Github Bot 4
parent db3adb4445
commit 1f2027a1fe
2 changed files with 11 additions and 5 deletions

View File

@ -55,7 +55,10 @@ import com.android.build.OutputFile
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
* // for example, you might want to remove it from here.
* inputExcludes: ["android/**", "ios/**"]
* inputExcludes: ["android/**", "ios/**"],
*
* // supply additional arguments to the packager
* extraPackagerArgs: []
* ]
*/

View File

@ -49,6 +49,9 @@ gradle.projectsEvaluated {
// Bundle task name for variant
def bundleJsAndAssetsTaskName = "bundle${targetName}JsAndAssets"
// Additional packager commandline arguments
def extraPackagerArgs = config.extraPackagerArgs ?: []
def currentBundleTask = tasks.create(
name: bundleJsAndAssetsTaskName,
type: Exec) {
@ -72,11 +75,11 @@ gradle.projectsEvaluated {
// Set up dev mode
def devEnabled = !targetName.toLowerCase().contains("release")
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
commandLine "cmd", "/c", "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "true", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
commandLine("cmd", "/c", "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "true", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, *extraPackagerArgs)
} else {
commandLine "node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "true", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir
commandLine("node", "node_modules/react-native/local-cli/cli.js", "bundle", "--platform", "android", "--dev", "${devEnabled}",
"--reset-cache", "true", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, *extraPackagerArgs)
}
enabled config."bundleIn${targetName}" ||