Skip to content

Commit a0d8740

Browse files
Maksym Rusynykfacebook-github-bot
Maksym Rusynyk
authored andcommitted
Android template: Allow overriding default "index.js" entry file (#26769)
Summary: - Using "System.getenv" allows to specify any entry file using environment variables and without modifying gradle file. Example: export ENTRY_FILE="another_entry_file.js" ./gradlew assembleDebug - This functionality is also more align with iOS implementation that uses 'if [[ "$ENTRY_FILE" ]]; then'. See #23667 for more details. - Possibility to define entry file on CI without modifying sources (Example: project like [pixels-catcher](https://www.npmjs.com/package/pixels-catcher) requires different entry file) ## Changelog: [Android] [Added] - Custom entry file on android using `ENTRY_FILE` environment variable Pull Request resolved: #26769 Test Plan: - Create a project from template - Define `ENTRY_FILE` environment variable ``` export ENTRY_FILE="anotherIndexFile.js" ``` - Build android ``` ./gradlew assembleDebug ``` Expected result: App contains bundle file that starts from `anotherIndexFile.js` file. Differential Revision: D17903165 Pulled By: cpojer fbshipit-source-id: 6b7cdf229918d101c170aa5fbdca6f3ef293d41c
1 parent fc25f28 commit a0d8740

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

react.gradle

+14-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ import org.apache.tools.ant.taskdefs.condition.Os
77

88
def config = project.hasProperty("react") ? project.react : [];
99

10+
def detectEntryFile(config) {
11+
if (System.getenv('ENTRY_FILE')) {
12+
return System.getenv('ENTRY_FILE')
13+
} else if (config.entryFile) {
14+
return config.entryFile
15+
} else if ((new File("${projectDir}/../../index.android.js")).exists()) {
16+
return "index.android.js"
17+
}
18+
19+
return "index.js";
20+
}
21+
1022
def cliPath = config.cliPath ?: "node_modules/react-native/cli.js"
1123
def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js"
1224
def bundleAssetName = config.bundleAssetName ?: "index.android.bundle"
13-
def entryFile = config.entryFile ?: "index.android.js"
25+
def entryFile = detectEntryFile(config)
1426
def bundleCommand = config.bundleCommand ?: "bundle"
1527
def reactRoot = file(config.root ?: "../../")
1628
def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"]
@@ -149,7 +161,7 @@ afterEvaluate {
149161
hermesFlags = config.hermesFlagsDebug
150162
if (hermesFlags == null) hermesFlags = []
151163
}
152-
164+
153165
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
154166
commandLine("cmd", "/c", getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags)
155167
} else {

template/android/app/build.gradle

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ import com.android.build.OutputFile
1515
* // the name of the generated asset file containing your JS bundle
1616
* bundleAssetName: "index.android.bundle",
1717
*
18-
* // the entry file for bundle generation
18+
* // the entry file for bundle generation. If none specified and
19+
* // "index.android.js" exists, it will be used. Otherwise "index.js" is
20+
* // default. Can be overridden with ENTRY_FILE environment variable.
1921
* entryFile: "index.android.js",
2022
*
2123
* // https://facebook.github.io/react-native/docs/performance#enable-the-ram-format
@@ -76,7 +78,6 @@ import com.android.build.OutputFile
7678
*/
7779

7880
project.ext.react = [
79-
entryFile: "index.js",
8081
enableHermes: false, // clean and rebuild if changing
8182
]
8283

0 commit comments

Comments
 (0)