Ever tried to speed up the Android-Emulator? You can tweak the emulator by using a snapshots to increase the booting performance of the emulator and apply some nasty registry hacks to tweak the speed at runtime. However, applying all of those tweaks improve the performance insignificant. Developing and especially debugging android applications with the emulator provided by the SDK is pain in the ass.
The Android-x86 Project
There is a solution to increase the debugging performance dramatically. Instead of running an emulator that emulates a real ARM processor with a lot of overhead, there is the Android-x86 project. It’s an open source project, that provides the ability to run Android directly on top of your x86 CPU.
You can run Android-x86 on most popular Virtual Machines like VMWare, QEmu and VirtualBox. I successfully tried to run it on all of those 3 Virtual Machines and I recommend VirtualBox for this approach, since it’s free and doesn’t need any special configurations to run smooth and very very fast.
Setting up Android-x86 with VirtualBox
At the first step we need the installation image of Android-x86. I used the the android-x86-2.3-RC1-eeepc.iso that can be downloaded here: http://www.android-x86.org/download.
Let’s create a Virtual Machine that will be able to run this image. I used the following setup for my machine:
- target OS: Linux
- target OS version: other
- 1 GB RAM
- a dynamically sized VDI drive, 500 MB
Now mount the image to the machine, boot it and choose "Installation – Install Android-x86 to harddisk".
During the installation you have to create a new partition, don’t forget to make it bootable:
- select "Create" by using the arrow keys
- select "Primary"
- set the preferred size, or simply hit enter
- select "Bootable"
- select "Write"
- confirm by typing "yes"
- select "Quit"
Once the partition is created properly you will be able to choose and format it.
Now complete the installation with the following steps:
- format sda1 as ext3
- click "yes" to install the Grub boot loader
- you may click also "yes" to install the /system directory as read-write
After those steps you have to reboot. Although our installation is complete and bootable, I suggest to make some changes for enabling other screen resolutions.
Changing Screen-Resolution
The screen resolution can be added as a booting parameter, or you can use a parameter that lets you choose the resolution every time the system boots. To do so, we need to change the configuration of the Grub boot-loader. Since we are not able to access the configuration from within our installed system, boot again from the image and choose "Live CD - Debug mode".
Now we have to mount our booting partition and edit the "menu.lst", containing our boot menu and the booting parameters.
mkdir /boot
mount /dev/sda1 /boot
vi /boot/grub/menu.lst
Let’s take a look at the lines, starting with "kernel" – as you can see, there are already few parameters passed to the kernel. There is also the option "androidboot_hardware" that we want to change to "generic_x86", since we are not using an EeePC.
To select the resolution at start up we have to add the "vga=ask" parameter and could change the line to something like this:
kernel /android-2.3-RC1/kernel quiet root=/dev/ram0 androidboot_hardware=generic_x86 acpi_sleep=s3_bios,s3_mode vga=ask SRC=/android-2.3-RC1
If you want to add a specific resolution directly to a boot menu entry, simply add the "DPI" and "UVESA_MODE" parameters instead:
kernel /android-2.3-RC1/kernel quiet root=/dev/ram0 androidboot_hardware=generic_x86 acpi_sleep=s3_bios,s3_mode DPI=240 UVESA_MODE=480x720 SRC=/android-2.3-RC1
You have to save the menu.lst after editing (press ESC and type :wq).
We are now ready to start the installed system – don’t forget to unmount the image first!
Booting the System and getting the Mouse to work
The booting performance is really great, isn’t it? As you might doubt out, your mouse is not yet working within the VM – click "Disable Mouse Integration" on the "Machine" menu or press Host key + I.
The default keyboard layout of your Android-x86 system:
- "Windows Key" corresponds to the Android Home button
- ESC corresponds to the Android back button
- F2 corresponds to the Android menu button
- F3 corresponds to the Android search button
- Alt+F1 switches to console mode
- Alt+F7 switches to GUI mode
Connecting as Android Virtual Device
To establish a connection between the host and the Android-x86 system and using the VM as AVD you have to configure the networking options of your VM. There are different ways to get this done. The simplest solution to connect both systems would be the usage of the "Host-only Adapter". Go to your VM network settings and change the "Attached to:" option to "Host-only Adapter".
Once you have set up the network, start your VM and use the "netcfg" command to output the actual network configuration of your Android system. You should get something like 192.168.56.101 for the VM and the host will be bound to 192.168.56.1.
On the host go to your SDK tools and start "adb" with the "connect" parameter:
adb connect 192.168.56.101
Congratulations! You now have a fully functional and very very fast AVD, running inside of a VM and booting in a blink of an eye.
You are now also able to select the newly created AVD as device in Eclipse.