Unable to load script.Make sure you are either running a Metro server or that your bundle 'index.android.bundle' is packaged correctly for release

后端 未结 30 1887
你的背包
你的背包 2020-11-28 19:16

react-native run-android command terminates by leaving a message in android simulator. The message is as follows:

Unable to load script.Make

相关标签:
30条回答
  • 2020-11-28 19:52

    update this part in metro blacklist

    var sharedBlacklist = [
      /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
      /website\/node_modules\/.*/,
      /heapCapture\/bundle\.js/,
      /.*\/__tests__\/.*/
    ];
    
    0 讨论(0)
  • 2020-11-28 19:52

    By default a tiny JavaScript server called "Metro Server" runs on the port 8081.

    You need to make this port available for this Server to start. So,

    1. release the port
    2. close your virtual device
    3. "react-native run-android" again.

    How to release the port?

    http://tenbull.blogspot.com/2019/05/how-to-kill-process-currently-using.html

    How to kill the process currently using a port on localhost in windows?

    and most importantly, I upgraded my node version from 8.x to 10.x(latest), as suggested by facebook @ https://facebook.github.io/react-native/docs/getting-started

    0 讨论(0)
  • 2020-11-28 19:53

    For me this problem started with upgrading react-native. The upgrade was necessary to add 64-bit support.

    Before:
    -------- 
    Environment:
    Node: 10.15.0
    npm: 6.9.0
    Watchman: 4.9.0
    Xcode: Not Found
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    
    Packages: (wanted => installed)
    react: 16.0.0-alpha.12 => 16.0.0-alpha.12
    react-native: ~0.55.2 => 0.55.4
    react-native-cli: 2.0.1
    
    After:
    ------
    info 
    React Native Environment Info:
    Binaries:
    Node: 10.15.0
    npm: 6.9.0
    Watchman: 4.9.0
    SDKs:
    Android SDK:
    API Levels: 23, 26, 27, 28
    Build Tools: 27.0.3, 28.0.3
    System Images: android-28 | Google APIs Intel x86 Atom
    IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5692245
    Xcode: /undefined - /usr/bin/xcodebuild
    npmPackages:
    react: ^16.8.6 => 16.9.0 
    react-native: 0.59.9 => 0.59.9 
    npmGlobalPackages:
    create-react-native-app: 2.0.2
    react-native-cli: 2.0.1
    

    Also, One important change that I made for the upgrade was in ../android/build/build.gradle

    android {
        ...
        defaultConfig {
            ...
            targetSdkVersion 28
            ...
        }
        ...
    }
    

    I had to change the targetSdkVersion from 27 to 28 following warning when I tried to upload the build(.apk) to goole play console. Little did i realise that this was the root cause of the above error for me. Immediatly answers by @tom and @tinmarfrutos made absolute sense.

    I solved the problem by adding android:usesCleartextTraffic="true" to my android/app/src/debug/AndroidManifest.xml

    0 讨论(0)
  • 2020-11-28 19:55

    This worked for me after trying several ways.

    In the file node_modules\metro-config\src\defaults\blacklist.js

    Replace :

    var sharedBlacklist = [
      /node_modules[/\\]react[/\\]dist[/\\].*/,
      /website\/node_modules\/.*/,
      /heapCapture\/bundle\.js/,
      /.*\/__tests__\/.*/
    ];
    

    with :

    var sharedBlacklist = [
      /node_modules[\/\\]react[\/\\]dist[\/\\].*/,
      /website\/node_modules\/.*/,
      /heapCapture\/bundle\.js/,
      /.*\/__tests__\/.*/
    ];
    

    hope this helps.

    0 讨论(0)
  • 2020-11-28 19:58

    For me this error was caused by an upgrade of react-native

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

    If you check out the upgrade diff you need to create a debug manifest android/app/src/debug/AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
        <application android:usesCleartextTraffic="true" tools:targetApi="28" tools:ignore="GoogleAppIndexingWarning" />
    </manifest>
    

    See for more info: https://stackoverflow.com/a/50834600/1713216

    https://react-native-community.github.io/upgrade-helper/

    0 讨论(0)
  • 2020-11-28 19:58

    I was having the same trouble, the problem for me was that adb was not in the right environment path, the error is telling you metro port, while you're in the adb, ports are killed and restarted.

    Add Enviroment Variable (ADB)

    1. Open environment variables
    2. Select from the second frame PATH variable and click edit option below
    3. Click on add option
    4. Submit the sdk platform tools path C:\Users\ My User \AppData\Local\Android\Sdk\platform-tools

    Note: Or depending where is located adb.exe in your machine

    1. Save changes

    Run android build again

    $ react-native run-android
    

    Or

    $ react-native start
    

    $ react-native run-android
    
    0 讨论(0)
提交回复
热议问题