The slowness of the Android emulator has been the butt of many a joke since it was first unveiled. While Google has done a commendable job of making each iteration of the emulator faster, it is still painfully slow. Most Android developers simply debug to a device and avoid the headache. But that is still far from an ideal solution. I for one, don't want my phone tied to my dev box. Also when I give talks, it is nice to be able to easily project my work, holding my phone in the air for the audience is not an ideal solution. I ran across a blog post by Chris Muir of Oracle, which offered a way out of emulator hell. The solution is to use a VirtualBox VM with Android on it instead of the Android emulator. Before you go all out and start putting together your own VM, be forewarned that entails a lot of work. You have to setup an x86 VM, deploy Android O/S to it, install software, etc. A lot of work. Luckily, the good folks at AndroVM have already done this work. The difference is amazing. I have tried it on both Mac and Windows. Assumptions This post is not to help you with setting up your Android development environment. I am assuming that your have already done that. The Android Device Bridge, which is included in the Android Developer Tools (ADT), should be installed and available on the command line (Windows) or terminal (Mac/Linux). To begin, we need to download VirtualBox from VirtualBox.org. This is Oracle's excellent and free virtual machine app, and yeah I know a company named Innotek originally created it, then Sun bought them and Oracle bought Sun. Once you have VirtualBox installed proceed to AndroVM and download the VMs. My recommendation is to grab the following:
These are the tablet (tp) and phone (p) versions of Android 4.1.1 with Google apps and other stuff. You will also be able to download, assuming you have a Google account, stuff from the Play Store. Once you have the VMs downloaded as OVA files you will need to import them.
With both VMs imported into VirtualBox I would recommend that you clone each and only use the cloned version. This is just a safety precaution against accidentally screwing up one of VMs.
To clone a VM simply right click it. Choose clone. Give the new machine a name. Mine's is x86Phone and x86Tablet, for the phone and tablet respectively. Choose the Full clone.
Then click the Clone button. It shouldn't take too long for the new VM to be available. Then right click one of the new VMs and click Settings... Click the Network tab. I have only been able to get the Bridged Adapter working. Change the connection so it matches the one below. A network connection is critical, without it you won't be able to deploy and debug your apps to the VM.
Click the Start arrow. In just a few seconds, yes seconds, your VM should spin all the way up. Unlock it and find the AndroVM Configuration program. It is usually on the home page in the lower left hand corner. Click it. It should display your emulator's IP address in the upper left corner. If it doesn't, STOP. You may need to go back to the network settings and jiggle them.
In order to deploy to the VM, the ADB needs to know that it exists. Simply open a command or terminal window and type the following command:
adb connect <ip address>
Note that the ip address is the same one shown by the AndroVM Configuration app. Now that the ADB knows it is there. Let's deploy something to it. First, we need to change our configuration to point to a USB device and not the emulator.
And we have a fast emulator. And it works like any other emulator except it is really fast.
Beware. This is not a Google sponsored project, so don't expect any kind of support. Also AndroVM has recently been acquired and it will be re-released in a few months as a commercial product. So if you are at all interested in a fast emulator, go and download it now!
PhoneGap/Cordova is a really cool framework for making mobile apps, but there is a dark side that isn't talked about enough. How to debug your apps? If you are writing any kind of non-trivial app, you will need something more than console.log and a lot of patience to debug your app. A partial solution to this issue is the Chrome Dev Tools. I say partial because apps which rely heavily on PhoneGap features won't work in Chrome, but if your app is more like a mobilized web site, you may benefit from this info.
I am assuming that you already have an app or two that you want to debug, so I won't cover anything about building PhoneGap apps here. I am just going to cover setting things up so you can use Chrome's Dev Tools to debug your app. This is the Windows 7 version of the instructions. I will post the Mac version in a day or two.
All of my PhoneGap apps share the same parent directory, "Repo". So what I propose to do is, make Repo a web site. Now, some people I've talked to prefer to make each individual app its own website. If you do too, this technique will still work for you, just change the location of the website's directory.
Begin by starting Internet Information Services 7 aka IIS7.Mine's just happens to be on the start page. Normally it would be under Adminstrative Tools.
On the left side, expand your computer name by clicking the disclosure triangle (my computer's name is TROYMILESF42B).
Expand the Sites list too.
Right click on Sites.
Click Add Web Site...
Give the site a name, mines is "Repos".
Select an Application Pool, I chose ASP.NET v4.0.
Select the path to your root folder.
If your machine runs with security, you may need to give it a user account to run against.
I highly recommend setting the port to something other than port 80, I am using 8088.
Make sure the "Start Web site immediately" check box is set.
Using Chrome, navigate to your website.
Enter Ctrl+Shift+I to open Chrome's developer's tools.
Click on the Sources tab, then the click the disclosure arrow on the top left side to show the source files.
Double click a file name to open it.
To set a break point simply click a line number along the left side. Click it again to disable the break point. Right click it and click, Remove breakpoint, to remove it.
This is Great but...
This is all great but we still have a problem. We no longer have a "deviceready" event, so this may break your code. For example, my compass app won't work without the PhoneGap enhancements to the navigator object. But strictly HTML sites will be good to go now.
I am still working on a partial solution to the "deviceready" issue, but it is not ready yet. It is suffice to say that it just mocks the event and places some test values data into the navigator object.