11

I am having working React Native application having version 0.38.0, when i have tried to upgrade it to 0.45.1 it is showing following error

java.lang.RuntimeException: Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctly or you're running a packager server.
at com.facebook.react.cxxbridge.CatalystInstanceImpl.jniLoadScriptFromAssets(Native Method)
at com.facebook.react.cxxbridge.CatalystInstanceImpl.loadScriptFromAssets(CatalystInstanceImpl.java:198)
at com.facebook.react.cxxbridge.JSBundleLoader$1.loadScript(JSBundleLoader.java:33)
at com.facebook.react.cxxbridge.CatalystInstanceImpl.runJSBundle(CatalystInstanceImpl.java:216)
at com.facebook.react.ReactInstanceManager.createReactContext(ReactInstanceManager.java:994)
at com.facebook.react.ReactInstanceManager.access$600(ReactInstanceManager.java:109)
at com.facebook.react.ReactInstanceManager$4.run(ReactInstanceManager.java:746)
at java.lang.Thread.run(Thread.java:761)

I have tried following solutions but it didn't work for me

SO: unable to load script from assets index.android.bundle on windows
SO: react native android failed to load JS bundle

pix
  • 1,264
  • 19
  • 32
Ravi
  • 34,851
  • 21
  • 122
  • 183

5 Answers5

28

1- Create a new folder => android/app/src/main/assets
2- Run this command =>

 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  

This command will create 2 files : index.android.bundle & index.android.bundle.meta

3- run command => react-native run-android

pix
  • 1,264
  • 19
  • 32
f.jafari
  • 568
  • 3
  • 10
  • 4
    `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` ---- For me, I have no **index.android.js**, so change it to **index.js**, this solves my issue. Thanks for the answer! – LiuWenbin_NO. Nov 23 '17 at 08:41
  • 1
    @LiuWenbin_NO I also needed to alter the solution a little. I actually deployed through Android Studio. It did however work as expected. – Culzean Dec 01 '17 at 10:33
  • if you don't have `index.android.js` it will automatically consider `index.js` – Hamza Waleed Sep 20 '22 at 13:01
6

Add these lines

project.ext.react = [ entryFile: "index.js", bundleAssetName: "index.android.bundle", bundleInAlpha: true, bundleInBeta: true ]

before apply from: "../../node_modules/react-native/react.gradle" in build.gradle

gderaco
  • 2,322
  • 1
  • 16
  • 18
3

Okay. Every answers are unique depending on 'when' and 'the version' at the time the problem occur.

Today is 27 August 2018 ( 1.2 years from this page posted) and I still found the same problem when I install react-native and create projects (on windows) by following the official website instruction.

And honestly it is very difficult to find the right answer to make it work like 'normal' for 'today', because everything has changed and is different from the time that has been left behind.

Now for the above question : Unable to load script from assets 'index.android.bundle'.

Meaning that we don't have the file as requested in the directory assets. That's all the problem!. There is no relation to port, devices, emulator etc.

Now what we need to do is to make the file is 'exist there'. And these are some options to you can do depending on your package configuration :

Create the directory 'assets' if not exist as requested in directory android/app/src/main/ or you can type in the console : mkdir android/app/src/main/assets

In your project directory, execute :

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

Then check in the asset folder if the files is already there. If not, then try the second way :

1 react-native start // open npm window popup

2 curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"

Then check in the asset folder if the files is already there. If not, then you need to down grade your project to earlier version packages. Follow these 5 steps and must complete one by one :

1 npm remove --save react-native
2 npm i --save react-native@0.55.4
3 npm remove babel-preset-react-native
4 npm i --save babel-preset-react-native@2.1.0

5 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

If you already have the files in asset folder, then you can continue your project.

Check if your device is connected and ready, and run-android :

adb devices

Make sure you get result like this :

List of devices attached
cb8eca15        device

Then run :

react-native run-android

Note : Alternatively, you can create a new project again with a specified version :

react-native init ProjectName --version 0.55.4

Sulung Nugroho
  • 1,605
  • 19
  • 14
2

To resolve Unable to load script from assets index.android.bundle - React Native follow below process :

You have to create dir assets manually in your android project or make Directory by Terminal/CMD enter mkdir android/app/src/main/assets

Go at the created Directory if that is successfully created then

run step 3 Command:

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

you have your missed files in the folder now you can Run your React Native project npm run android.

https://stackoverflow.com/a/53275340/9489285

Hemant Sharma
  • 259
  • 5
  • 14
0

In my case, the emulator was on airplane mode. Make sure your emulator or mobile phone can communicate with the Metro server.

Dipo
  • 507
  • 7
  • 10