I'm running Android Studio (currently in version 3.6.1) under Ubuntu 18.04 in WSL 2 (Windows 10 2004), which now supports GUI. Since virtualization inside WSL2 doesn't work, I need to keep running my emulator on the host and of course, connected devices which I use for debugging my android app appear on the host.
How can Android Studio see the emulator and devices appearing on the host?
In WSL2 terminal, run adb connect PHONE_ID:5555. You will be prompted to confirm the connection on your phone. Do that. adb will probably fail because of the connection confirmation. Run adb kill-server in the WSL2 terminal and then run adb connect PHONE_ID:5555. If Android Studio was open in WSL2, close it and then open it again.
Just look around for how to run GUI apps on WSL2. You will need to install a desktop shell, enable remote desktop services on wsl and then connect to it using remote desktop. Then you have Linux desktop, you can install whatever you want. There is a way for the connected devices, but this has to be done one by one:
A limitation is that WSL2 does not support nested virtualization at this time, so you will not be able to emulate an virtual Android device. Not the answer you're looking for?
Looks like WSL ip isn’t visible from within the emulator. You need to connect to windows ip and add a port forwarding in the same way as for metro bundle netsh interface portproxy add v4tov4 listenaddress=0.0.0.0 listenport=3333 connectaddress=$WSL_CLIENT connectport=3333 Hope this helps.
There is a way for the connected devices, but this has to be done one by one:
adb tcpip 5555
adb connect [ip device]:5555
and in android studio should you see the device
Here's what I had to do based on this Medium post.
adb
to the environment variables on Windows. From File Explorer, right-click on This PC
and then choose Advanced system settings
, then Environment Variables.
Under System variables, look for Path
, click Edit
, and then New
. Add this path: C:\Users\MYUSERNAME\AppData\Local\Android\Sdk\platform-tools
. Make sure to change MYUSERNAME.adb
to your PATH. You need to make sure that you are using the same version of adb
on Windows and Linux, which is why I installed the latest Android Studio on both. In my case, I added alias adb='/home/MYUSERNAME/Android/Sdk/platform-tools/adb'
to my .bashrc
.adb devices
. Make sure the device is there.adb tcpip 5555
.adb devices
. You will not see any device yet, but this will start up adb
.Settings
-> About phone
-> Status
-> IP address
. It will probably be something like 192.168.0.10n
.adb connect PHONE_ID:5555
.adb
will probably fail because of the connection confirmation. Run adb kill-server
in the WSL2 terminal and then run adb connect PHONE_ID:5555
.Finally your device is available to debug!
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