Unable to load script from assets index.android.bundle on windows

Problem: Unable to load script from assets index.android.bundle on windows

I’m trying to run my first React Native project for the first time on my device (Android 4.2.2).

And I get:

unable to load script from assets index.android.bundle

Commands that I used:

  1. cd (project directory)
  2. react-native start
  3. react-native run-android

Solutions of Unable to load script from assets index.android.bundle on windows

Solution 1: Unable to load script from assets index.android.bundle on windows

I’ve encountered the same issue while following the React Native tutorial (developing on Linux and targeting Android).

This issue helped me resolve the problem in the following steps.

  1. (in the project directory) mkdir android/app/src/main/assets
  2. 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
  3. react-native run-android

You can automate the above steps by placing them in scripts part of package.json like this:

"android-linux": "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"

Then you can just execute npm run android-linux from your command line every time.

Solution 2: Unable to load script from assets index.android.bundle on windows

If You are running your application on a physical device and getting this error

unable to load script from assets index.android.bundle

try running the command:

adb reverse tcp:8081 tcp:8081

It worked for Me…

Solution 3: Unable to load script from assets index.android.bundle on windows

I spent hours trying to figure this issue out. My problem was not specific to Windows but is specific to Android.

Accessing the development server worked locally and in the emulator’s browser. The only thing that did not work was accessing the development server in the app.

Starting with Android 9.0 (API level 28), cleartext support is disabled by default.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest ...>
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        ...
        android:usesCleartextTraffic="true"
        ...>
        ...
    </application>
</manifest>

Solution 4: Unable to load script from assets index.android.bundle on windows

I’ve had this same issue for a number of months now. I initially used @Jerry’s solution however, this was a false resolution as it didn’t fully fix the problem. Instead, what it did was take every build as a production build meaning that any slight change you made in the app would mean that rebuilding the entire app is necessary.

While this is a temporal solution, it works horribly in the long term as you are no longer able to avail of React Native’s amazing development tools such as hot reloading, etc.

A proper solution is shown:

In your MainApplication.java file, replace the following:

@Override
public boolean getUseDeveloperSupport() {
    return BuildConfig.DEBUG;
}

with

@Override
public boolean getUseDeveloperSupport() {
    return true;
}

for some reason BuildConfig.DEBUG always returned false and resulted in a bundle file in the assets directory.

By manually setting this to true, you’re forcing the app to use the packager. This WON’t work in production so is sure to change it to false or the default value.

Don’t forget also to run

$ adb reverse tcp:8081 tcp:8081

Solution 5: Unable to load script from assets index.android.bundle on windows

 Go to your project directory and check if this folder exists android/app/src/main/assets

  1. If it exists then delete two files viz index.android.bundle and index.android.bundle.meta
  2. If the folder assets don’t exist then create the assets directory there.

2. From your root project directory do

cd android && ./gradlew clean

3. Finally, navigate back to the root directory and check if there is one single entry file calledindex.js

  • If there is only one file i.e. index.js then run the following 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
  • If there are two files i.e index.android.js and index.ios.js then run this 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
    1. Now run react-native run-android

Conclusion

I hope the Unable to load script from assets index.android.bundle on windows The solution would be useful for you to learn something new from this solution. If it helped you then don’t forget to bookmark our site for more Quiz Answers and solutions.

check out on stack overflow

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!