expo - 无法连接到 TCP 端口:尝试在 WSL2 中的 Android 模拟器上打开 Expo 应用程序时连接被拒绝
问题描述
我一直在关注本指南https://medium.com/@pellea/using-adb-with-wsl2-7aebbb070a47到目前为止,WSL2 可以通过 Android Studios 看到在 Windows 上运行的模拟器-> AVD 管理器。例如,在 Windows 和 WSL2 上,adb devices
正确显示:
List of devices attached
emulator-5554 device
但是,当我转到我的 expo 应用程序并尝试启动 Android 模拟器时,我收到以下错误消息:
Couldn't start project on Android: could not connect to TCP port 5554: Connection refused
这是在我尝试了以下操作之后:
ADB_SERVER_SOCKET=tcp:<MY IP>:5037
在我的 WSL2 配置文件中导出- 通过(来自上面的链接)从我的 Windows 防火墙解除阻止 WSL2 vEthernet 连接
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
- 我已将 5554 从 Windows 移植到 WSL2,以及 5037(从 0.0.0.0 到 127.0.0.1):
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'";
$WSL_CLIENT -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
$WSL_CLIENT = $matches[0];
iex "netsh interface portproxy add v4tov4 listenport=5554 listenaddress=127.0.0.1 connectport=5554 connectaddress=$WSL_CLIENT"
端口如下:
netsh interface portproxy show all
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
127.0.0.1 8081 172.25.38.171 8081
0.0.0.0 5037 127.0.0.1 5037
127.0.0.1 5554 172.29.149.0 5554
解决方案
您是否尝试将端口 5554 映射到 Windows IP?(或本地主机)。Android 模拟器是在 Windows 上运行的,而不是 WSL2,所以端口代理应该是从 WSL2 到 Windows,而不是向后。
您是否已经以其他方式解决了它?
推荐阅读
- c - Different results in linux OS than my Windows OS
- c# - 应该在 Web API 控制器中投射什么?
- google-sheets - Google Sheets: Use ArrayFormula for JoinText for multiple columns
- python - 显示每个月 DataFrame 的前 5 个最大值
- flutter - Flutter 离线数据安全
- python - django.core.exceptions.ImproperlyConfigured。即使我尝试了所有配置方法,我也会收到相同的错误
- javascript - 使用 require 无法在反应中加载本地 img
- python - 使用 python 应用程序查找应用程序的路径
- android - PhilJay / MPAndroidChart 图表冻结 UI
- r - 热图绘制时间与日期 ggplot