2022-02-11

Tech Programing

程式人小天地

Could not connect to TCP port: Connection refused when trying to open Expo app on Android Emulator in WSL2

1 min read


I’ve been following this guide https://medium.com/@pellea/using-adb-with-wsl2-7aebbb070a47 and so far have gotten to the point where WSL2 can see the emulator(s) running on Windows through Android Studios -> AVD manager. For example, on both Windows and WSL2, adb devices correctly shows:

List of devices attached
emulator-5554   device

However, when I go to my expo app and try to launch the Android emulator, I get the following error message:

Couldn't start project on Android: could not connect to TCP port 5554: Connection refused

This is after I’ve tried the following:

  1. exporting ADB_SERVER_SOCKET=tcp:<MY IP>:5037 in my WSL2 profile(s)
  2. Unblocking WSL2 vEthernet connections from my Windows firewall via (from the above link)
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
  1. I’ve portforwarded 5554 from Windows to WSL2, as well as 5037 (from 0.0.0.0 to 127.0.0.1):
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inets)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"

The ports are as follows:

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



Source link

資料來源:Stackoverflow

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *