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?
Make sure your device is not connected as a media device. Can confirm that this is critical! On Android 5.0, go to Settings -> Storage -> menu -> USB computer connection and make sure 'Media device (MTP)' is disabled. When it's disabled 'adb devices' lists the device, when enabled not.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With