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.

Created on 7 Nov 2019  Â·  12Comments  Â·  Source: facebook/react-native

React Native version:

Steps To Reproduce

1.
2.

Describe what you expected to happen:

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

Bug Android 📦Bundler

Most helpful comment

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

  1. Move to the project folder.
    cd MyApp
  2. 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)
  3. 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
  4. > react-native run-android
    Then, it started working.
    Hope this helps.

All 12 comments

The same problem on Windows 10. I tried suggestions found on web but no success.

react-native-cli: 2.0.1
react-native: 0.59.10

The same problem I am facing. Upgrading node, clearing cache none of it worked

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

  1. Move to the project folder.
    cd MyApp
  2. 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)
  3. 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
  4. > 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.

Awesome it works, finally. Thank you so much

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. You may also label this issue as a "Discussion" or add it to the "Backlog" and I will leave it open. Thank you for your contributions.

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

I still have that problem.

Also still having that problem on 0.63.2

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 :point_up: 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! :tada:

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

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"
    ...
Was this page helpful?
0 / 5 - 0 ratings

Related issues

lazywei picture lazywei  Â·  3Comments

josev55 picture josev55  Â·  3Comments

axelg12 picture axelg12  Â·  3Comments

anchetaWern picture anchetaWern  Â·  3Comments

ghost picture ghost  Â·  3Comments