Here’s the situation. I’ve really been digging into the Natty Narwhal release of Ubuntu over the past few weeks, and felt the time was right to switch over to doing as much as I can on the OS on a more permanent basis. However, I still can’t seem to get away from Win7 as a primary OS. I still enjoy the occasional (sometimes more) FPS and have a health Steam account, and unfortunately Wine, Crossover, and VMWare’s guest DirectX acceleration just don’t cut it. After plenty of testing on that front I’ve settled on maintaining Win7 as my host operating system, but have been running Natty Alpha (now Beta) pretty much full screen front and center in both VMWare and VirtualBox guest virtual machines, settling on VirtualBox for the long haul. I still think VMWare Player is the overall better solution for VMs these days, but hardware graphics acceleration still isn’t supported for linux guests, and Unity is so very pretty that way.
So life is good, aside from the occasional Compiz crash, and my Eclipse dev enviroment is set up in the virtual machine, and not unexpectedly the first time I spin up an android emulator it just hangs. I’m not going to spend a lot of time on that since I’ve got an old HTC Eris to use for development and debugging anyway. Not as unexpectedly, the process of actually getting that talking to the debugger is… less than automagic.
But with a little effort it can be done, and after a little digging it’s pretty simple. I’m going to assume if you’ve read this far you a) have too much time on your hands and b) know enough to be able to debug android apps in an emulator or device under more normal circumstances. This little snippet strictly targets the process of making it happen within a VirtualBox guest. It so happens I’m running VirtualBox version 4.04 hosting Ubuntu 11.04 on a Windows 7 host, if you haven’t picked up on that yet.
To start off with, you’ll want to to have the VirtualBox extension pack installed which supports USB 2.0 devices. I’m also running the most current virtualbox-ose-* tools from synaptic rather than the closed source version provided by VirtualBox, since they are currently a bit buggy. The main point of contention seems to be that VirtualBox is very picky about being the sole owner of the USB connection, so you need to set up a device filter for your android device so that it’s picked up by VirtualBox before your host OS sees it. Plug in the Android device and make sure you’ve got any necessary drivers installed so your host recognizes it. Power down your VM. In the VirtualBox Manager, select the virtual machine, right click -> settings, select USB. Ensure Enable USB Controller and Enable USB 2.0 (EHCI) are checked and click add on the right hand side. You should be able to select your Android device here. Now unplug you Android device and power on the VM. Make sure you follow the instructions here to make sure your ubuntu system recognizes the device. At this point you should be able to plug in the Android device and see it register with adb. Debug away, friends.
One thing I’ve noted is if you need to disconnect your Android device from the VM do so with the phsical cable. Don’t be cute and select disconnect from the device menu. This cedes control of the USB device back to your host OS, which tends to bork the connection in various ways, and you may not be able to regain a connection to your guest os without restarting. Or it might just take down the whole VM. I’ve seen it go both ways.