Could not connect to React Native development server on Android

前端 未结 28 1676
鱼传尺愫
鱼传尺愫 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:42

    ** Ubuntu Try running these commands both in your root folder only:

    1. sudo npm start --- this will pause automatically after saying -- Loading Graphs, done (something like this) ; when this is done -open another terminal

    2. react-native run-android


    If still the issue prevails, delete your build folder in android / ios execute this command and then execute the above mentioned commands in the same order

    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**
    
    0 讨论(0)
  • 2020-11-30 22:42

    To add to goldylucks's answer, you can use IP 192.168.0.10 if that is the IP of your PC running the React Native packager.

    You may need to open your firewall as well.

    In Ubuntu 18.04, you can get your IP by:

    ip -c addr show
    

    You will see your IP in there, something like: inet 192.168.0.10/24 brd 192.168.0.255 scope global dynamic noprefixroute enp0s25 (notice the 192.168.0.10 in my sample).

    Then, you could open port 8081 in your firewall, something like:

    sudo ufw allow 8081
    

    It will be using TCP, so make sure TCP is open on port 8081.

    Then you can follow goldylucks's answer and goto Dev settings and enter 192.168.0.10:8081 or whatever IP you need.

    You can test it from the browser on your device. While the packager is running from your PC, navigate to http://192.168.0.10:8081 from your mobile device and make sure it works. It will show something like "Packager running". It will be clearly working or failing.

    Goldylock's answer excites me because it solves the issue very nicely if you are having problems with that error messages. It sucks to have to rebuild the app all the time or worse yet, delete the APK off your device and then build again.

    As such, you should probably be using wifi as part of your dev strategy.

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

    I met this question too in native and react-native pro, my solution was:

    1. open npm server with npm start
    2. run native project with Android Studio
    3. transmission network request with adb reverse tcp:8081 tcp:8081
    4. when you need to reload the page, just input: adb shell input keyevent 82

    just keep it in order.

    P.S. if you ran a fail project, just run adb kill-server

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

    and first of all I appreciate you for posting your doubt. It's mainly because maybe your expo or the app in which you run your react native project may not be in the same local connected wifi or LAN. Also, there is a chance that there is disturbance in your connection frequently due to which it loses its connectivity.

    I too face this problem and I personally clear the cache and then restart again and boom it restarts perfectly. I hope this works for you too!

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