无法连接到Android上的React Native开发服务器 [英] Could not connect to React Native development server on Android

查看:283
本文介绍了无法连接到Android上的React Native开发服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行react-native run-android时,出现以下错误:

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

无法连接到开发服务器

Could not connect to development server

  • 打包服务器正在运行,我可以直接从浏览器访问它 在我的移动设备上.
  • 我的Android设备已连接到计算机并启用了调试功能(我 使用adb devices命令检查).
  • 我的Android版本是4.4.4,所以我不能使用adb reverse命令.
  • 我已经在开发设置中设置了ID地址和端口.
  • USB调试已打开.
  • 我使用Windows 7.
  • Package server is running and I can access it directly from browser on my mobile device.
  • My Android device is connected to computer and has debugging enabled (I checked using adb devices command).
  • My Android version is 4.4.4 so I cannot use adb reverse command.
  • I have set the ID address and port in Dev setting.
  • USB debug is on.
  • I use Windows 7.

如何解决此错误?

推荐答案

来自文档: http://facebook.github.io/react-native/docs/running-on-device.html#method-2-connect-via-wi-fi

方法2:通过Wi-Fi连接

Method 2: Connect via Wi-Fi

您还可以通过Wi-Fi连接到开发服务器.你会
首先需要使用USB电缆在您的设备上安装该应用,但是
完成后,您可以按照以下步骤进行无线调试
指示.您需要开发计算机的当前IP
继续操作之前的地址.

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.

打开一个终端,然后输入/sbin/ifconfig查找您机器的IP 地址.

Open a terminal and type /sbin/ifconfig to find your machine's IP address.

  1. 确保您的笔记本电脑和手机位于同一Wi-Fi网络上.
  2. 在设备上打开您的React Native应用.
  3. 您将看到一个红色屏幕,并显示一个错误. 没关系.以下步骤将解决此问题.
  4. 打开应用内开发人员菜单.
  5. 转到开发设置→调试设备的服务器主机.
  6. 输入计算机的IP地址和本地开发服务器的端口(例如10.0.1.1:8081).
  7. 返回开发人员"菜单,然后选择重新加载JS".
  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.

这篇关于无法连接到Android上的React Native开发服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆