[react-native]could not connect to development server on android

匿名 (未验证) 提交于 2019-12-03 02:18:01

问题:

When I run "react-native run-android",it gives me error:"could not connect to development server...".

  • Package server is running and i can access it directly from browser in mobile device.
  • My android device connected to computer has debugging enabled i checked it using adb devices command.
  • My android version is 4.4.4 so i cannot use adb reverse command.
  • I have set the ip address and port in Dev setting.
  • Usb debug is on.
  • OS is windows7.

So how to fix the red error screen issue?Any suggestion is appreciated!

enter image description here

回答1:

From the Docs: http://facebook.github.io/react-native/docs/running-on-device.html#method-2-connect-via-wi-fi

Method 2: Connect via Wi-Fi

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 /sbin/ifconfig to find your machine's IP address.

  1. Make sure your laptop and your phone are on the same Wi-Fi network.
  2. Open your React Native app on your device.
  3. You'll see a red screen with an error. This is OK. The following steps will fix that.
  4. Open the in-app Developer menu.
  5. Go to Dev Settings → Debug server host for device.
  6. Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
  7. Go back to the Developer menu and select Reload JS.


回答2:

f you are trying to debug app in your physical android device over wifi using a windows machine, then the device may not be able to access the port of your pc or laptop, you have to make the port accessible. this involves two steps:

1.First create a rule in firewall. for doing this follow the following steps:

open run dialog -type wf.msc -click on inbound rules -click new rule on right hand side -select port from pop up menu and click next -select tcp port and specific local ports and enter the port number like 8081(default) -allow the connection -select all in profile section -give some appropriate name and description -click finish

  1. you have to make your pc accessible to outside, for doing this follow the following steps: -open network and sharing centre from control panel -change adapter settings -select your wifi network -right click, properties -click on sharing tab -check all the checkboxes

You are good to go, now try running react-native run-android.



回答3:

We faced this issue, In order to fix this, solution is dead simple is below.

  1. Cancel the current process of“react-native run-android” by CTRL + C or CMD + C
  2. Close metro bundler window command line which opened automatically.
  3. Run the command again, “react-native run-android”.

Basically this error tells that your current build got failed due to reasons like Code issue or dependency issue.

Click here for more details



回答4:

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



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!