Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unable to load script from assets 'index.android.bundle'

I'm new in react-native. I have run react native project on Ubuntu by using 'react-native run-android' command. And I got the error on emulator "Unable to load script from assets 'index.android.bundle'.Make sure your bundle is packaged correctly or you are running a package server."

like image 378
YB Tester Avatar asked Jun 20 '17 09:06

YB Tester


3 Answers

I also got this and I resolved this using following commands in your project directory:

$ mkdir android/app/src/main/assets

$ react-native bundle --platform android --dev false --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

$ react-native run-android
like image 189
Nilesh Modak Avatar answered Oct 12 '22 11:10

Nilesh Modak


In my case (embedding React Native as a new Activity into an existing Android Code Base), the problem was Android Studio had auto-imported the wrong BuildConfig.

Wrong: import com.facebook.react.BuildConfig;

Right: import com.mywebdomain.myapp.BuildConfig;

This would apply to the wherever you are housing this block of code:

mReactRootView = new ReactRootView(this);
mReactInstanceManager = ReactInstanceManager.builder()
        .setApplication(getApplication())
        .setBundleAssetName("index.android.bundle")
        .setJSMainModulePath("index")
        .addPackage(new MainReactPackage())
        .setUseDeveloperSupport(BuildConfig.DEBUG)
        .setInitialLifecycleState(LifecycleState.RESUMED)
        .build();
like image 22
grailian Avatar answered Oct 12 '22 10:10

grailian


Using npm version 4.3.0 react-native-cli version 2.01 react-native version 0.49.5

In project directory,

  • mkdir android/app/src/main/assets
  • react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
  • react-native run-android

The file name has changed from index.android.js to index.js

like image 13
Darshan Pania Avatar answered Oct 12 '22 11:10

Darshan Pania