Getting either no devices listed or just
adb devices when running adb in a virtual machine? My setup is VirtualBox running Ubuntu 18.04 LTS hosted in Windows 10 machine. Connecting one of my Android devices with Lineage 16 and running adb in the VM doesn’t make the device ask for debugging authorization. When connecting with adb from the host machine, it does.
The solution is inspired by this stackoverflow post, with few modifications.
On both the host and the virtual machine make sure the version of adb is exactly the same. Otherwise the client will ask the server to restart and unexpectedly fail, when using the below provided solution.
For instance, Firefox for Android build uses internally adb version 1.0.41. But the system wide adb (up to date) in Ubuntu is 1.0.39. To download platform-tools for Windows, in my case, with that version you have to hack the URL bar a bit as there are no download links on the android site for older versions. Trial and error got me this link to get the tools with adb version 1.0.39 for Windows.
On the host machine:
- Connect the device with USB debugging enabled, as usually
- Don’t connect it in the running VirtualBox VM
adb devicesto check the host machine sees the devices, check the server has started on port 5037
On the virtual machine:
- Make sure the adb server is not running with
- Check nothing listens on the 5037 port with
netstat -nao | grep :5037
socat tcp-listen:5037,fork tcp:10.0.2.2:5037where 10.0.2.2 should be the host address as seen from the VirtualBox VM
- You should see the same result as on the host machine and be able to work with the device now
The trick is to simply forward the TCP traffic between the two machines and pretend a server in the VM. It can work well the other way around with any kind of direct TCP relay in Windows, any kind of port and any IP address of choice.
I wrote this more for myself to not forget till next time, but maybe it will help someone.