可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
- 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.
- Open the in-app Developer menu.
- Go to Dev Settings → Debug server host for device.
- Type in your machine's IP address and the port of the local dev server (e.g. 10.0.1.1:8081).
- 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
- 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.
- Cancel the current process of“react-native run-android” by CTRL + C or CMD + C
- Close metro bundler window command line which opened automatically.
- 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