question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

index.android.js and index.ios.js should be unified also in build.gradle and iOS build file

See original GitHub issue

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",

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:3
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
fiznoolcommented, Nov 30, 2017

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);
  }
}
6reactions
Jp3rdcommented, Nov 2, 2017

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native project do not have index.ios.js or index.android.js
For the latest version of React native(0.49.3), it seems that the "index.android.js" and "index.ios.js" separate entry routes are no longer ...
Read more >
Config Plugins - Expo Documentation
Learn about config plugins, which are the Expo way of customizing the prebuild phase of an project.
Read more >
Plugin Reference - NativeScript Docs
A collection of reference material for NativeScript plugin authors, including a plugin's required folder structure, npm configuration, and gradle ...
Read more >
Realm: Create reactive mobile apps in a fraction of the time
Realm JavaScript enables you to efficiently write your app's model layer in a safe, persisted and fast way. It's designed to work with...
Read more >
Releasing Updates - Visual Studio App Center | Microsoft Learn
ios.js or index.js ). However, all of these defaults can be customized to allow incremental flexibility as necessary, which makes it a ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found