Could not connect to React Native development server on Android

前端 未结 28 1672
鱼传尺愫
鱼传尺愫 2020-11-30 22:10

When I run react-native run-android, it gives me the following error:

Could not connect to development server

相关标签:
28条回答
  • 2020-11-30 22:17

    None of the above solutions worked for me.

    I just opened Dev menu by clicking Ctrl+M and then clicked on change bundle location and added my machine IP followed by port.

    0 讨论(0)
  • 2020-11-30 22:19

    Basically this error comes when npm server is not started.

    So at first check the npm server status, if it's not running then start npm with command npm start and you can see in terminal:

    Loading dependency graph done.

    Now npm is started and run your app in another terminal with command

    react-native run-android
    
    0 讨论(0)
  • 2020-11-30 22:21

    I've added <uses-permission android:name="android.permission.INTERNET" /> to debug/AndroidManifest.xml and it started working! I've removed it from main/AndroidManifest.xml and forgot to add in debug.

    ReactNative version is 0.61.2

    0 讨论(0)
  • 2020-11-30 22:21

    This is most probably a firewall issue. If someone using ubuntu faces this issue , then you can use

    sudo service iptables stop
    

    to disable the firewall for the port to be accessible

    0 讨论(0)
  • 2020-11-30 22:22

    n my case with Android 4.4.2 had to do some additional steps: (Make sure rn server is running npm start, delete app-debug.apk from android/app/build/outputs/apk , uninstall from android if previously installed and run following commands from root folder)

    1_ create dir mkdir android/app/src/main/assets
    2_ create file index.android.js which is a clone of index.js cp index.js index.android.js
    3_ react-native link
    4_ curl "http://localhost:8081/index.android.bundle?platform=android" -o "android/app/src/main/assets/index.android.bundle"
    5_ react-native run-android
    
    0 讨论(0)
  • 2020-11-30 22:23

    Solution for React-native >V0.60

    You can also connect to the development server over Wi-Fi. You'll first need to install the app on your device using a USB cable, but once that has been done you can debug wirelessly by following these instructions. You'll need your development machine's current IP address before proceeding.

    Open a terminal and type ipconfig getifaddr en0 For MAC

    Make sure your laptop and your phone are on the same Wi-Fi network. Open your React Native app on your device.

    You'll see a red screen with an error. This is OK. The following steps will fix that.

    1. Open the in-app Developer menu. shake your phone or press CMD/ctrl + M
    2. Click on Settings
    3. click on Debug server host & port for device
    4. On popup Type your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
    5. Go back to the Developer menu and select Reload.

    DONE

    0 讨论(0)
提交回复
热议问题