Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 '(?<=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"

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
like image 917
Richard Avatar asked Nov 16 '22 03:11

Richard


1 Answers

Just had the same issue with Expo.

Here is what fixed it for me:

  1. Check for a process that uses port 5555 (Terminal)
    netstat -ano | findstr 5555
    
  2. Kill the process using its ID (PowerShell)
    Stop-Process -ID [PROCESS_ID] -Force
    

Then it started working.

like image 138
Kaloyan Drenski Avatar answered Dec 30 '22 20:12

Kaloyan Drenski