React-native: index.android.js and index.ios.js should be unified also in build.gradle and iOS build file

Created on 30 Oct 2017  路  11Comments  路  Source: facebook/react-native

Is this a bug report?

Yes

Have you read the Contributing Guidelines?

Yes

Environment

Environment:
OS: Windows 10
Node: 8.5.0
Yarn: 1.2.1
npm: 5.5.1
Watchman: Not Found
Xcode: N/A
Android Studio: Version 2.3.0.0 AI-162.4069837

Packages: (wanted => installed)
react: 16.0.0-beta.5 => 16.0.0-beta.5
react-native: 0.49.5 => 0.49.5

Steps to Reproduce

(Write your steps here:)

  1. react-native init
  2. cd android && ./gradlew assembleRelease

Expected Behavior

Assemble release should go fine but...

Actual Behavior

I receive: Cannot find entry file index.android.js in any of the roots:

And this is because (in case of android) after the upgrade with react-native-git-upgrade, the build gradle file didn't change and the entry file is specified as below:

```

  • // the entry file for bundle generation
  • entryFile: "index.android.js",
Android iOS Ran Commands Locked

Most helpful comment

I've found that you need both the changes to the build.gradle file and your MainApplication.java file for this to work, and it's also important where you put these lines of code in the two files.

build.gradle

Put the following in your android/app/build.gradle file, above the line that contains apply from: "../../node_modules/react-native/react.gradle"

project.ext.react = [
    entryFile: "index.js"
]

Make sure you use the correct build.gradle file - you want the one inside the app folder.

MainApplication.java

Put the following in your MainApplication.java file, which will be located inside a subdirectory tree in the android/app/src folder:

@Override
protected String getJSMainModuleName() {
  return "index";
}

This needs to live inside the call to new ReactNativeHost(this). Here's an example of how it appears in my workspace:

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new VectorIconsPackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

All 11 comments

Actually modifying the file android/app/build.gradle doesn't even work... What this could be?

Experiencing the same issue after upgrading from 0.48.3 -> 0.49.5.

I removed index.ios.js and index.android.js in favor of just "index.js", and changed this my react entry file point:

project.ext.react = [
    entryFile: "index.js"
]

Some other fixes I've seen have suggested running react-native start with "reset-cache", but that did not work for me either.

I tried reset-cache too but it didn't work

add this code inside the method "mReactNativeHost" of the MainApplication.java file. This should work :)
@giacomocerquone

@Override
 protected String getJSMainModuleName() {
        return "index";
 }

Can someone (from react native team) change this automatically when developers upgrade from older versions?

I have the same issue, on android I get the same error message: "Cannot find entry file index.android.js in any of the roots:".
Tried adding that line of code, but didn't work. I think I have tried everything mentioned on this topic but still no luck.

@Jp3rd That didn't help, that method was even already there and it still has problems building my apk for release.
Any clue?

Same issue here. Have both

project.ext.react = [
    entryFile: "index.js"
]

and

@Override
 protected String getJSMainModuleName() {
        return "index";
 }

and running with start --reset-cache but still not working, anyone have any ideas?

I've found that you need both the changes to the build.gradle file and your MainApplication.java file for this to work, and it's also important where you put these lines of code in the two files.

build.gradle

Put the following in your android/app/build.gradle file, above the line that contains apply from: "../../node_modules/react-native/react.gradle"

project.ext.react = [
    entryFile: "index.js"
]

Make sure you use the correct build.gradle file - you want the one inside the app folder.

MainApplication.java

Put the following in your MainApplication.java file, which will be located inside a subdirectory tree in the android/app/src folder:

@Override
protected String getJSMainModuleName() {
  return "index";
}

This needs to live inside the call to new ReactNativeHost(this). Here's an example of how it appears in my workspace:

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new MainReactPackage(),
            new VectorIconsPackage()
      );
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

Still no fix for this? Updated rn to 0.51.0 and it still gives me troubles

@fiznool not work for me 鈽癸笍

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as "For Discussion" or "Good first issue" and I will leave it open. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings