Repository navigation
ADB in WSL2 #4692
Replies: 15 comments 10 replies
|
Hi! We've identified this issue as a duplicate of another one that already exists in this repository. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report! |
|
TCP bridge. Likely dupe #4619 but having pulled the trigger too fast once already will let it float. |
|
Workaround didn't work for me... |
|
Gustavo Lopes (@gusflopes) For me it was windows firewall issue, check your firewall settings, after correcting that it worked. |
|
Alright so here's what you're gonna do: Add the following to your WSL bashrc or zshrc: Then create a firewall entry, create a new "Inbound" Rule. Select "Port" then Specific TCP port "5037" then "Allow the connection" then check all of Domain, Private and Public and add a name. After the firewall entry is added, open up its properties, go to Scope -> Remote IP Addresses -> Add "172.16.0.0/12". Now that we're covered in the WSL2 VM and through the Firewall, you have to start the adb server with specific arguments to make it listen on all addresses (don't worry we've only whitelisted our WSL2 VM IP range so no security issues). Create a vbs script, call it whatever and put this in it Now all you have to do is invoke the vbs script once per reboot and your WSL VM will connect to your host ADB instance |
|
I was able to connect over wifi without the need of installing on both sides. See - https://developer.android.com/studio/command-line/adb/?gclid=CjwKCAjw2dD7BRASEiwAWCtCbxKzwu63T-HpLaIp8ASO1aNA6aRl7_8Wvc2LqCvf3BI3umOlQQaOtBoCQrEQAvD_BwE&gclsrc=aw.ds#wireless |
|
This one ("used to work on WSL1 but no longer in WSL2") is #4619. It's analogous X11 Server on Windows, Database server on Windows, etc etc. Rather than dupe, porting over to the discussion forum for tips/tricks ADB over TCP with WSL2. Thanks for the input everyone. |
|
I was using Intellij''s Android developement setup inside of WSL2. IntelliJ/Android Studio does not let you set the The fix I came up with was to use export WSL_HOST_IP="$(tail -1 /etc/resolv.conf | cut -d' ' -f2)"
socat TCP-LISTEN:5037,reuseaddr,fork TCP:$WSL_HOST_IP:5037Make sure to run this in a separate process before starting up Intellij/Android Studio, since the IDE will start up an adb server if it detects that one is not yet running. Once it starts up the server, you will not be able to run the above socat command, and it will result in an error of something to the effect of |
|
Getting I have set those environment variables in WSL And starting WSL2 distribution adb Windows adb WSL |
|
After two days of research, here is what helped solve my problem in my case. In my case, the device used port 21503. Therefore, the command looked like: Then run More information here https://learn.microsoft.com/en-us/windows/wsl/networking In fact, for me this was the only option since I couldn't use WSL 1 (which connects to localhost without problems since it is not a VM). |
|
For the wireless-device case mentioned a few times above: the setup that's been painless for me is to not run a Linux adb server inside WSL2 at all — call the Windows The remaining friction is No usbipd, no firewall rules, no port proxying. |
|
To fix all of those problems , try these.
You should see: adb.exe Then run You should get: List of devices attached Make it convenient
To make the alias permanent:
|


Uh oh!
There was an error while loading. Please reload this page.
ADB (Android Debug Bridge) used to work on WSL1 but no longer in WSL2
The catch was to use the same version in both windows and linux
WSL1

WSL2

OS

All reactions