For certain projects, you may find that the default Android emulator is far too slow for accurate testing.
In this guide, I will show you how to set up a faster alternative. I will be using Windows, but the tools are platform-agnostic, so you shouldn’t have trouble setting up a faster Android emulator on a Mac or a Linux box. I will also show you how to configure the resolution of the new Android emulator so you can emulate specific Android devices, such as the Amazon Kindle Fire.
First, download and install VirtualBox. We’ll be running our faster Android emulator as a virtual machine. You can probably use VMWare, or Parallels, but VirtualBox is available free of charge, and works perfectly well for our purposes.
Now, download the Android image. For this guide, I will be using Android 2.3 (Gingerbread). For that release, the matching download is android-x86.2.3-4th-test-110620.iso.
Start VirtualBox and create a new virtual machine.
Enter a name for your new virtual machine. Select Linux for the operating system, and Other Linux for the version.
I want my Android emulator to run with 1 GB of RAM. You can choose whatever amount of memory is best for your needs.
For Virtual Hard Disk, check Start-up Disk, and choose to Create a new hard disk.
Select VDI (VirtualBox Disk Image) for the type of virtual disk.
Choose Dynamically Allocated storage.
For disk size, I tend to allocate 512 MB. Feel free to allocate more or less disk space for your new emulator.
Once this is done, continue with the last few dialog boxes to create the new Android virtual machine.
Click on Audio, and change the Audio Controller from ICH AC97, which doesn’t work very well with this setup, to SoundBlaster 16.
Click on Network, and change the setting to Host-only Adapter. Now, this bit is specific to your particular network configuration. Some folks claim that setting this to NAT or Bridged Adapter gives best results. Use whichever works best for your rig. I will proceed with Host-only Adapter.
Click on Storage. Under Storage Tree, click on the icon to add a new CD/DVD device. When prompted, click on Choose Disk, and select the Android .iso image you downloaded earlier.
Start the new virtual machine. When prompted, choose Install Android-X86 to harddisk.
When prompted to choose a partition, select Create/Modify partitions. In the cfdisk partition manager screen that follows, choose New, then Primary, and keep the default partition size. Toggle Bootable, and then proceed to Write. After the partition is created, choose Quit to exit cfdisk. Select the newly created partition, and choose ext3 for the filesystem format. Select Yes when prompted to install the boot loader GRUB, and Yes to make the /system directory read-write. Installation should take just a few seconds.
After installation, close the virtual machine and remove the Android .iso CD/DVD in the Storage Settings before starting the virtual machine again.
When you start the new Android virtual machine, you’ll notice that you cannot use your mouse inside the Android OS. To fix this, choose Machine from the VirtualBox menu, and then choose to Disable Mouse Integration. You will now be able to use the mouse inside the Android OS. Take note of the host key used by your installation of VirtualBox. Without this host key, you won’t be able to get your mouse back out of the Android OS. I believe that the default host key used by VirtualBox on Windows is the right Control key, but this may be different in your installation. Click inside the Android virtual machine to bring your mouse into that environment. Click on the host key to get the mouse back out.
To test your application in the new Android emulator from Eclipse, you’ll need to know the IP address of the virtual machine. Click ALT-F1 to bring up the VirtualBox console, and type netcfg to display the IP address assigned to it. Take note of the IP address and click ALT-F7 to get rid of the console.
You can now connect the Android Debug Bridge (adb) to the new virtual machine Android emulator. Bring up a command prompt window, and type adb connect 192.168.56.102. Of course, you’ll use the IP address of your virtual machine, which may be different. If your system can’t find adb.exe, add it to your environment PATH. You’ll find adb.exe in your Android SDK installation directory.
Now you can set up a new Run Configuration in Eclipse to test your application in the new Android emulator. When setting up a new Run Configuration in Eclipse, click on the Target tab, and select a Manual deployment target.
Once this is done, when you choose to Run your application from Eclipse, you’ll be presented with a dialog from which you can select the Android device on which to run your application. Since you connected adb to your new Android virtual machine, you should see the IP address of the virtual machine as one of the available devices on which to test.
What if you need to run the Android virtual machine with a custom resolution?
I’m going to configure my new emulator to look like the Amazon Kindle Fire, which has a DPI of 169 with a resolution of 1024 x 600.
First, in your VirtualBox, right click on your new virtual machine, and choose Show in Explorer. This will show you the location of the .vbox configuration file for the new VM. We’re going to edit this file, but first, we’ll need to close VirtualBox, and close our virtual machine, if it’s running.
Edit the .vbox file; it’s just an XML configuration file.
Find the ExtraData section, and add a line to it declaring your custom resolution:
<ExtraData> <ExtraDataItem name="GUI/LastCloseAction" value="powerOff"/> <ExtraDataItem name="GUI/LastGuestSizeHint" value="800,600"/> <ExtraDataItem name="GUI/LastNormalWindowPosition" value="998,300,800,639"/> <ExtraDataItem name="CustomVideoMode1" value="1024x600x16"/> </ExtraData>
I added the CustomVideoMode1 line above.
Save and close the configuration file.
Now, start your virtual machine, and when you see the GRUB boot loader screen, choose Debug Mode.
At the command prompt that follows, type the command vi /mnt/grub/menu.lst to edit the GRUB boot menu file.
You should probably be familiar with the vi editor for this part. If you aren’t, find a quick tutorial to familiarize yourself with the basics.
Duplicate one of the existing entries in the file to create a new one, then change its title to something more meaningful, change its DPI parameter to 169 (that’s what we want from our Amazon Kindle Fire emulator), and add the parameter vga=ask to the end of the line.
Save, close the file, and restart the virtual machine.
You will see the new boot entry as one of the menu items on the GRUB loading screen.
When you select the new boot entry, you’ll be given the option to hit ENTER to see the available resolutions (you entered vga=ask in the GRUB configuration file, remember?). Your new entry, 1024x600x16, will be one of the items.
And here’s our new Android emulator running at a resolution of 1024×600 and a DPI of 169 — all ready for you to test your Amazon Kindle Fire applications.
That should be all. I’m sure you’ll find that the Android emulator running as a virtual machine is far more responsive that the standard emulator. Happy testing!
If you make mobile apps for a living, check out Uberdeck. It’s a service we started to allow mobile app developers to make more money from their apps, and to prevent negative reviews.