microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.52k stars 822 forks source link

Unable to connect to an ADB device in WSL 2 running on Windows 10 #10044

Open Anantha-sb opened 1 year ago

Anantha-sb commented 1 year ago

Windows Version

Windows 10

WSL Version

WSL version: 1.2.5.0

Are you using WSL 1 or WSL 2?

Kernel Version

Kernel version: 5.15.90.1

Distro Version

22.04

Other Software

No response

Repro Steps

Steps to reproduce: I have been trying to run detox on WSL 2 but no luck no matter how many solutions I try. I have done my complete setup (java, nodejs, android-studio, yarn, npm, everything needed) in WSL 2. From these, I am able to build both binaryPathand testBinaryPath.

When I try to connect ADB from WSL 2, and when I try the command yarn detox:e2e:android-debug, Detox fails to install / run the test apks.

These are the solutions I have tried:

Pre-req:

  1. Configure PORTS 5555, 5037, 5556 and allow inbound traffic in windows firewall to accept all connections (public, private)
  2. Add new inbound and outbound rule for adb.exe located installed in Windows C.
  3. Use USBIPD in Windows and USBIP in WSL 2

Method 1 - Connect using the PORT 5555

Windows cmd: adb kill-server Windows cmd: adb start-server Windows cmd: adb tcpip 5555

WSL2: adb connect :5555

Error - Failed to connect :5555, No Host to Route.

Method 2 - Connect by using the variable ADB_SERVER_SOCKET=tcp::5037

Windows cmd: adb -a -P 5037 nodaemon server start Windows cmd: adb devices -> Device gets listed

WSL2: adb devices -> Device gets listed and I can runadb logcat and I can even install the react apk built at binaryPathbut the apk generated at testBinaryPathdoes not get installed.

Error:

adb.exe I 04-28 18:34:17 24176 10752 transport.cpp:1727] fetching keys for transport 19287B2023
adb.exe I 04-28 18:34:17 24176 10752 auth.cpp:468] Calling send_auth_response
adb.exe I 04-28 18:34:17 24176 10752 auth.cpp:435] Calling send_auth_publickey
adb.exe I 04-28 18:34:20 24176 10752 adb.cpp:176] 19287B2023: offline
adb.exe E 04-28 18:37:03 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)
adb.exe E 04-28 18:37:08 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)
adb.exe E 04-28 18:37:13 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)
adb.exe E 04-28 18:37:18 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)
adb.exe E 04-28 18:37:23 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)
adb.exe E 04-28 18:37:28 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)
adb.exe E 04-28 18:37:33 24176 10752 services.cpp:83] failed to connect to socket 'tcp:33999': cannot connect to 127.0.0.1:33999: No connection could be made because the target machine actively refused it. (10061)

Method 3 - Wi-Fi Debugging

Android: Enable Wi-Fi debugging

WSL2: adb connect :5556 - This works flawlessly on a Mac but not in WSL2.

Expected Behavior

I want to be able to connect an android adb device in WSL 2 running on Windows 10.

Actual Behavior

Please refer above. I am able to use adb logcat and the device gets listed in WSL2 but I am not able to send / receive ping to my android device. Host is unreachable. Adb adb_connection_refused

Diagnostic Logs

No response

paddyfink commented 9 months ago

@Anantha-sb hello, did you resolve this? I'm facing the same issue

daehwankim112 commented 4 months ago

I am having a same issue

velrino commented 1 month ago

same issue here