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.