ADB device list empty using WSL2

15,067

Solution 1

This answer worked for me using WSL 2:

On Windows:

adb tcpip 5555

Then on WSL 2:

adb connect [ip device]:5555

If it's the first time, it's going to ask you for permission in your phone, make sure to check the box to always grant permission. Then restart adb and connect again:

adb kill-server
adb connect [ip device]:5555

You can get your [ip device] from: Settings > About device > Status. It has a form like: 170.100.100.100

Solution 2

Jorge's answer is fine, but beginners like me may need some more details.

[ip device] is [YOUR_PHONE_IP] address. To get the IP address of your phone, go to "Settings -> About phone -> Status -> IP address". It will probably be something like 192.168.x.y.

I did not add adb to my PATH variable - neither in Windows nor in Linux/WSL2. Instead I just downloaded the latest version for both OS's using the links below:

https://dl.google.com/android/repository/platform-tools-latest-linux.zip https://dl.google.com/android/repository/platform-tools-latest-windows.zip

Once I unzipped platform-tools I had to change directory to the unzipped folder (cd platform-tools) in both PowerShell and WSL2.

Then in PowerShell on Windows, I run .\adb tcpip 5555 in the platform-tools folder.

In WSL2 terminal, I run ./adb connect 192.168.2.199:5555 (where 192.168.2.199 was my PHONE_IP address).

The first time you connect using [YOUR_PHONE_IP] address, you will be prompted to confirm the connection. The adb might say it failed to connect while it was waiting for the confirmation. If so, run ./adb kill-server in the WSL2 terminal and then run ./adb connect [YOUR_PHONE_IP]:5555 again.

You can display the list of attached devices via .\adb devices in PowerShell and ./adb devices in WSL2.

That is all. Now you should be able to debug your phone using WSL2.

Share:
15,067
Ian
Author by

Ian

I'm an enthusiastic JavaScript and C# developer who enjoys challenging problems. I've recently been involved purely in JavaScript development working on Single Page Applications and visualizations.

Updated on June 06, 2022

Comments

  • Ian
    Ian 12 months

    I'm trying to debug / connect up a device for development using WSL2 (Ubuntu). I've followed steps on this post https://stackoverflow.com/a/58229368/21061 which sets up ADB on both Windows and Linux using the same ADB version.

    Once I've done that however, I get an empty list of devices in the Ubuntu terminal. I've tried killing and restarting the ADB server from the Windows command line and that doesn't seem to make any difference. Is this not possible in WSL2 or is there something I'm missing?

  • Marek Urbanowicz
    Marek Urbanowicz over 2 years
    I am getting unable to connect to 172.19.112.1:5555: Connection timed out
  • Jorge Guillermo Negrete
    Jorge Guillermo Negrete over 2 years
    @MarekUrbanowicz Which versions are you using? Is working for me using ADB 1.0.41 version 30.0.5-6877874, make sure both ADB are the same version. Check if your pc and phone are using the same network. Check if adb devices on Windows shows your phone when is plugged to the pc. Also maybe your firewall is blocking the connection
  • NotTheDr01ds
    NotTheDr01ds about 2 years
    Definitely enough new and useful information here to be worthy of a new answer, IMHO. Thanks for the information, and Welcome to Stack Overflow.
  • Davidou
    Davidou about 2 years
    @NotTheDr01ds Thanks for the corrections and a warm welcome : )
  • Slion
    Slion over 1 year
    To switch back to USB mode use: adb usb
  • Slion
    Slion over 1 year
    Great stuff, used this to fetch blobs as I'm attempting a Lineage OS build from WSL.
  • Erick Adam
    Erick Adam over 1 year
    Thanks, it works. But for some reason, I'm getting an endless loop of "#Waiting for application to start"
  • Shawn
    Shawn about 1 year
    I'm using a device (not a phone, can think it as a raspberry pi board), and it doesn't have Ip (no ethernet connection on it yet), then how to access it in wsl2 via adb devices?
  • Shawn
    Shawn about 1 year
    looks like the adb in WSL2 directly connect to your phone(as ./adb connect yourPhoneIP:5555), then what is the purpose of running adb tcpip 5555 on windows?