react-native: Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.

React Native version:

Steps To Reproduce

Describe what you expected to happen:

Snack, code example, screenshot, or link to a repository:

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 32 (1 by maintainers)

Most upvoted comments

I have the same issue after upgrading from react-native 0.61.5 to 0.63.2.

  • Debug mode works fine, when running npx react-native run-android and yarn start in a separate terminal window.
  • Release build works fine, when running npx react-native run-android --variant=Release.
  • Staging build installs without problems but crashes after splash screen, when running npx react-native run-android --variant=Staging. When running from Android Studio it logs the ☝️ error:

Unable to load script. Make sure you’re either running a Metro server (run ‘react-native start’) or that your bundle ‘index.android.bundle’ is packaged correctly for release.

These are the buildTypes settings in my android/app/build.gradle (working fine for previous versions of react-native):

    buildTypes {
        debug {
            resValue "string", "CodePushDeploymentKey", '""'
        }
        staging {
            resValue "string", "CodePushDeploymentKey", '"******"'
            signingConfig signingConfigs.release
            matchingFallbacks = ['release']
        }
        release {
            minifyEnabled enableProguardInReleaseBuilds
            proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
            resValue "string", "CodePushDeploymentKey", '"******"'
            signingConfig signingConfigs.release
        }
    }

Please help! All the “solutions” I found so far were either suggesting to start a Metro Instance, or adding an assets folder (which already exists in my project), or running a three-lines-long bundle command – but surely there must be a better way!?

Update: Adding bundleInStaging: true to my app/build.gradle as suggested in this answer solved this problem for me! 🎉

I have solved the problem using the below steps.

  1. Updated nodejs to the latest version.
  2. Deleted the all the contents from .gradle(C:/Users/xxx/.gradle) folder (You may skip this in the initial attempt)
  3. I created project using,

    react-native init MyApp

  4. Move to the project folder.

    cd MyApp

  5. I was getting some blacklist.js some character issue. For that I referred this link and replaced sharedBlacklist character set. (https://stackoverflow.com/questions/58120990/how-to-resolve-the-error-on-react-native-start/58122821#58122821)
  6. Next, I ran the below code snippet to address the bundle issue.( Ref Link : https://medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff)

    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

  7. react-native run-android Then, it started working. Hope this helps.

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

Hi everybody~

### Here is my solution

None of the above solutions can solve my problem but only follow the below steps working for me. Add in network-security-config.xml file

    <domain-config cleartextTrafficPermitted="true">
          <domain includeSubdomains="true">10.0.2.2</domain>
    </domain-config>
    ...

Then update AndroidManifest.xml file with

<application
+   android:networkSecurityConfig="@xml/network_security_config"
    ...

Same here using npx react-native run-android --variant=release. I’ve used ./gradlew clean into android folder but the issue persists. No sign of this problem in debug mode. I’m using RN 0.69.3.

If you are encountering this issue on Android 28+ in Debug Mode, make sure you add this to your AndroidManifest.xml:

<application
+   android:usesCleartextTraffic="true"
    ...

In my case, the app was running ok in Production Mode, but it didn’t start in Debug Mode. Because of some network security issues, the app was unable to connect to the Metro bundler, even when it was running.

Source: https://reactnative.dev/docs/integration-with-existing-apps#cleartext-traffic-api-level-28

For more details & more fine grained approaches: https://github.com/facebook/react-native/issues/22375

I still have that problem. someone help please. my emulator is not in airplane mode

I am having this issue in release mode

Im getting this error on real device. but not on emulator. I have tried few solutions mentioned above but none of them help me.

I tried executing network-security-config.xml change. It didnt help.

Then tried executing medium.com/@adityasingh_32512/solved-unable-to-load-script-from-assets-index-android-bundle-bdc5e3a3d5ff

But nothing works for me. only installing apk, on app start it throws the error always

Same thing for me. Did you ever get this working on a real device?

I’ve solved it in this way. Hope it helps.