首页 文章

React Native应用程序无法在Expo应用程序中启动

提问于
浏览
3

我安装了带有Expo的HTC M8s,我想测试用React Native编写的应用程序 . 我在控制台中运行我的应用程序,扫描QR码并尝试从我的智能手机连接到我的应用程序 - 不幸的是,我看到一个错误,说它无法加载exp:// myaddress:port .

我使用的是Windows 10,我的PC和智能手机都连接到同一个WiFi网络 .

这是 ipconfig 命令的结果:

Ethernet adapter Ethernet:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : myhostname.net

Wireless LAN adapter Wi-Fi:
   Connection-specific DNS Suffix  . : myhostname.guest
   Link-local IPv6 Address . . . . . : fe80::8136:d112:d190:5fd8%17
   IPv4 Address. . . . . . . . . . . : 10.168.4.171
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 10.168.4.1

Ethernet adapter Ethernet 6:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 1:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Ethernet 3:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Bluetooth Network Connection:
   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Tunnel adapter Local Area Connection* 11:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::1c40:2198:f557:fb54%11
   Default Gateway . . . . . . . . . :

这是运行 npm start 的结果:

(...) Or enter this address in the Expo app's search bar:

  exp://10.168.4.171:19000

不幸的是,我无法从智能手机中安装的Expo应用访问我的应用 .

我已经尝试过:

  • 在我的电脑上卸载了VirtualBox

  • 更改了网络适配器的优先级,以便WiFi具有最高优先级

我仍然无法通过Expo应用程序运行我的应用程序 . 然而,在我的电脑上安装Expo应用程序解决了这个问题 - 它显示了与控制台上不同的QR码,我可以运行我的本机应用程序,但我想从我的智能手机上运行我的应用程序来自Expo应用程序 .

编辑:我尝试使用Win10的另一台PC . 安装了create-react-native-app,运行它并通过WiFi完美运行 .

2 回答

  • 0

    我不确定你是否已经找到答案,但我希望这可以帮助那些面临同样情况的人 . 罪魁祸首是网络适配器 . 有一种称为网络适配器的接口度量,接口度量越低,适配器的优先级越高 . 我从windows透视图中写这个答案 . 正如您所提到的,您的电脑和手机已连接到同一个Wi-Fi网络,因此您无法在移动设备上访问该应用程序的原因是因为您启动服务器时获得的本地IP未分配给你想要的适配器 .

    • 以下解决方案对我有用:

    • 以管理员身份启动命令提示符,键入powershell .

    • 类型Get-NetIPInterface:这将为您提供网络适配器列表,索引号及其接口指标

    • 通过以下命令将wirelss适配器的接口度量标准更改为最小值:Set-NetIPInterface -InterfaceIndex "your_wifi_adapter_interface_index" -InterfaceMetric "MinimumValue"

    • 在控制台选项卡中键入"r",其中打开npm,以便重新启动打包程序 .

    • 瞧!有用 .

  • 0

    来源:https://github.com/react-community/create-react-native-app/issues/60#issuecomment-317104728我读了Himujjal's解决方案并且它适用于我:以下步骤肯定会有所帮助 . 我有同样的问题,并能够在我的Windows 10操作系统中解决它 . 我的计算机上安装了Virtual Box,我无法在我的android expo客户端中运行CRNA . 所以,

    • 首先我通过移动热点连接笔记本电脑 .

    • 然后按控制面板>(搜索'network connections')>网络连接

    • 右键单击'Wifi'>选择'Properties'> 'Internet Protocol Version 4 (TCP/IPv4)' [不取消选中标记]

    • 转到"Properties"> "Advanced...">(取消选中'Automatic Metric')>在下面的文本框中键入(Interface Metric):10 .

    • 单击确定,然后确定,然后确定:)

    • 然后对其他"Virtual Box-xxxxx"网络执行相同操作 . 但是将20放在Interface Metric文本框中 .

    • 单击“确定”,“确定”和“确定” .

    尝试在Expo上重新启动您的应用 . 它现在必须工作!

相关问题