Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native: Change the Entry file path index.android.js to specified custom file path

I need to change the Entry file path to src/XXXApp.android.js instead of pointing to default index.android.js file. I want to keep the JS file in seperate ./src folder.

So that I made the change in ./android/app/build.gradle like

 project.ext.react = [
    bundleAssetName: "src/XXXApp.android.bundle",
    entryFile: file("../../src/XXXApp.android.js"),
    root: "../../../../",
    inputExcludes: ["android/**", "./**"]
 ]

and in .\node_modules\react-native\react.gradle file like

def bundleAssetName = config.bundleAssetName ?:"src/XXXApp.android.bundle"
def entryFile = config.entryFile ?: "src/XXXApp.android.js"

But development package server always pointing to localhost:8081/index.android/bundle. . Manually i tried the URL: localhost:8081/src/XXXApp.android.bundle and it retrieve the data. But in device debug loadJs always try the localhost:8081/index.android/bundle.

Please share the solution, proper place to update the entry file config for android. Appreciate in advance for your valuable solution.

like image 556
tsb Avatar asked Sep 02 '16 12:09

tsb


People also ask

How do you change .gradle path for react native?

gradle . In Android Studio it's easily changed in the settings (Default settings > Build, Execution, Deployment > Build Tools > Gradle > Service directory path).

What is index js file in react native?

index.js is the starting point for React Native applications, and it is always required. It can be a small file that require s other file that are part of your React Native component or application, or it can contain all the code that is needed for it.


1 Answers

In your MainActivity you can override getJSBundleFile() method of ReactActivity. Here you can specify your bundle file name along with the path. Code push use same method of override reactjs bundle path.

like image 150
while1 Avatar answered Oct 04 '22 19:10

while1