Speeding up Android development with Android-x86 and VirtualBox
I’m starting to learn how to develop to Android and so far to me the only downside of the whole dev environment is the painfully slow Android Emulator. Don’t get me wrong, it’s such a beautifully made emulator that covers most (if not all) details of a real device, I specially like tricks such as limiting network bandwidth to simulate your app under a slow connection, but let’s face it, the thing is slow.
I have to say I don’t have a top of line computer either, it’s a Core 2 Duo with 4gb of RAM running Ubuntu 11.10 (amd64), so I started searching for tricks to speedup the emulator, until I found that Android-x86 can be used as a emulator. The experience is not as good as Google’s official emulator but with some tweaks you can really speedup turnaround both in boot time and overall execution speed. OK, TL;DR, enough small talk, let’s get down to business, click the following link to go to the full post
The Android-x86 project provides some ISO images that can be ran on VirtualBox (download it here if you don’t have it yet). I took the time to wrote the steps bellow based on various blog posts about the subject.
First, download an ISO from Android-x86 download page, android-x86-2.3-RC1-eeepc.iso should do, this one is pretty stable and has ethernet support. There is a RC1 honeycomb port here but I didn’t test it.
Now create a VM on VirtualBox, my settings were:
Linux / Linux 2.6, RAM: 256 MB, Fixed Size, 512 MiB VDI Disk
You can play with these options to find which ones fits better with your apps, for me 256 MiB was sufficient
OK, after that you need to setup the ISO file, to do this select your VM from the list and go to Settings / Storage, click on the disk icon and chose a virtual CD/DVD disk file. Select your ISO of choice
Now go to Network, there you have two easy options – If you have a router on your network, select Bridged Adapter and your internet connected adapter (mine is eth1). This is the easiest option in my opinion.
If you don’t have a router or if it didn’t work for any reason, select NAT. Using NAT you can’t connect directly to the device, but thankfully VirtualBox has a handy port forward feature. To use it you just need to click on Advanced / Port forwarding and add a rule like this one:
Note that no matter which mode you choose you need to click in advanced and select PCnet-FAST III as the Adapter Type.
You can also disable the USB controller if you don’t need it.
Now click OK and start up your VM. From the GRUB menu, select Install to Harddisk
Follow screen instructions. From the partition options menu select Create/Modify partitions, this will show you the partition manager (cfdisk), there, using the arrow keys, select New / Primary and specify the size (534.64 for me). Make the partition Bootable and select Write, after that select Quit to go back to the installation menu.
Select the recently created partition (sda1) and click OK. Now format the partition as ext3 and install GRUB.
When the installation asks if you want the system directory as read-write, answer Yes. Installation should not take long. You can create a fake SD card, I created an 128 MiB one. You can skip this step and select reboot.
Now that installation is done you can shutdown the VM, go to settings and remove the ISO from the settings menu, and start it again.
From the GRUB menu above, select Debug Mode to configure the screen resolution, here I created a 480×750 entry to better simulate a smartphone screen. To do this you need to run these commands:
mount -o remount,rw /mnt cd /mnt/grub vi menu.lst
This will open GRUB’s menu configuration with the default entries, you need to create a new entry with these options:
title Android-x86 2.3 Smartphone kernel /android-2.3-RC1/kernel quiet root=/dev/ram0 androidboot_hardware=eeepc acpi_sleep=s3_bios,s3_mode DPI=160 UVESA_MODE=480x800 SRC=/android-2.3-RC1 SDCARD=/data/sdcard.img
To go to edit mode on vi use the Insert key (to go to insert mode). After inserting the above lines save the file to disk: press Escape (to leave insert mode), then write
:wq on the bottom command line.
Now you need to umount the disk and reboot your VM, to do this execute these comands:
cd / umount /mnt reboot -f
And Done! Now let’s go to some needed adjustments…
After a couple seconds you’ll be greeted with Android’s home screen. Click on the VM screen, if the cursor don’t show up press
Right CTRL + i, click on the application menu icon and go to Settings. There, enable the Ethernet adapter. To go back to the home screen press
Win Key, to go back one screen press
Esc. To show the options menu press
If you choose NAT you’re ready to go, if you choose Bridged you need to get the VM’s IP, so press
ALT + F1 to go to the Busybox prompt and execute
Your network configuration will be printed to the console, to go back to the user interface press
ALT + F7.
Now you need to connect adb to be able to use the emulator from Eclipse.
Open a console and go to android sdk home/platform-tools, once there execute this for NAT:
adb connect 127.0.0.1
If you set networking as Bridged Adapter, execute this:
adb connect your-android-ip-see-netcfg-step-above
Done with the adjustments
Now go to Eclipse and run your project as an Android Application, if the device selection screen doesn’t show up go to Run Configurations and set the Android Launcher to use Manual selection.
Dpne! (for real this time)
I usually test using the official emulator once just to make sure everything is OK.
You can also download older versions of android from the android-x86 project website to simulate other devices. Hope it helps, if you have any problems let me know in the comments section