How to speed up the Android Emulator by up to 400%

Posted: December 7, 2012 in Android, mobile, tablet, Tech
Tags: , , , , , , , , , ,

Android-x86

android-x86

Fortunately there is an open source project porting Android OS to x86 CPUs: http://www.android-x86.org/.

The project provides several images, and even if they logically cannot keep up to date with all the Android SDK releases, they provide an image for Android 2.3 that is an interesting target.

Setting up Android_x86 with VirtualBox

The first step is to download an ISO image of Android_x86.
I used android-x86-2.3-RC1-eeepc.iso that can be downloaded from http://www.android-x86.org/download.

The next step is to create a Virtual Machine to be able to run this image.

I used Virtual Box for that, but from what I read, QEmu can be used too.

So in Virtual Box, you have to create a new machine:

  • target OS: choose Linux
  • target OS version: others
  • I used 1GB for RAM and 1 CPU (and left the other options at default)
  • add a new hard drive: VDI drive, dynamically sized, 512 Mio
  • on the storage add a CDROM pointing to the iso image you just downloaded.

On the boot menu select install to hard disk.

Install

During the set up, you will have to:

  • create a new partition
  • format it to ext3
  • select this partition for Android installation

Once set up is completed:

  • shutdown the VM
  • remove the CDROM device pointing to ISO (in VirtualBox configuration dialog).

Boot the VM; you should now have a running Android x86 image.

But since it is by default configured for an Eee PC, this is not ideal to test applications targeting a smart phone.

We will now change the configuration to match a phone screen.

Shutdown the VM and VirtualBox.

The first step is to define custom resolution modes. I defined 3 modes:

VBoxManage setextradata "Android2.3" "CustomVideoMode1" "320x480x16"
VBoxManage setextradata "Android2.3" "CustomVideoMode2" "640x960x16"
VBoxManage setextradata "Android2.3" "CustomVideoMode3" "480x720x16"

where “Android2.3″ is the name of the VM in VirtualBox.

Now that we have declared new modes, we need to use them. For that we need to change the kernel parameters.

In order to do so, you need to restart the VM and on the boot menu choose the Debug mode so that Android boots in command line.

Start the VM.

Once started, we will remount the boot partition in read/write so that we can change the Grub configuration.

mount -o remount,rw /mnt

Then you can edit the menu.lst file.

vi /mnt/grub/menu.lst

Then duplicate the first menu entry (3 lines) and then edit the kernel parameters
(the first “title” entry and two following lines.)

Default parameters are:

quiet root=/dev/ram0 androidboot_hardware=eeepc acpi_sleep=s3_bios,s3_mode DPI=240 SRC=/android-2.3-RC1

parameters I used:

quiet root=/dev/ram0 androidboot_hardware=generic_x86 acpi_sleep=s3_bios,s3_mode DPI=240 UVESA_MODE=480x720 SRC=/android-2.3-RC1

Set what you want for the title.

If you want to be able to select the resolution at boot time, you can also use:

quiet root=/dev/ram0 androidboot_hardware=generic_x86 acpi_sleep=s3_bios,s3_mode vga=ask SRC=/android-2.3-RC1

Save your menu.lst (:wq) and reboot the VM using the VirtualBox menu.

You should now be able to start an Android VM that looks like a phone.

Quick tips for using the VM:

  • if you don’t see the mouse on the Android screen, use the VirtualBox menu to disable mouse integration (Host key + I)
  • the “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 => switch to console mode
  • Alt+F7=> switch to GUI mode

Connecting the Android x86 VM to AVD and Eclipse

The goal is to be able to use the new VM from Eclipse using AVD to test and debug your app.
For this to work, you need the network config to allow connection between the host (where you run Eclipse) and the VM.
For that, inside VirtualBox you have several options in the Network settings:
- use Bridge mode: it will work but may require the presence of a DHCP server on the host
- host only network: uses an internal network between the VM and the host; this is the simplest solution.

VB_HostConfig

Once you have set up the network, restart the VM and go to command line mode (Alt+F1), and type:

netcfg

It will output the current IP of the VM.
Typically, you will have something like 192.168.56.101 for the VM and the host will be bound to 192.168.56.1.

On the host, open a command line and cd into the android platform-tools directory:

./adb connect 192.168.56.101This will register your VM as a new device:
 Adb-connect

You can now, directly from Eclipse, run and debug your application in the Android x86 VM.

As you will see, the speed improvement is very significant:

  • VM startup takes about 2s rather than 30s
  • Application run and debug is very fast (no lag like when using the ARM emulator).

Adding a SD card

You can use the documentation provided by http://www.android-x86.org/documents/sdcardhowto.

Using a file to fake a SD card

From the Android command line:

dd if=/dev/zero of=/data/sdcard.img bs=1024 count=65536 (64MB image)
losetup /dev/block/loop7 /data/sdcard.img
newfs_msdos /dev/block/loop7

Then restart the VM in debug mode, re-mount the partition in RW mode and edit menu.lst to add one parameter to the kernel:

SDCARD=/data/sdcard.img

Using a separated partition

This option requires a little more work.

You first have to create a new hard drive in VirtualBox and attach it to the VM.

Now start your VM in debug mode.
Use fdisk to create a new partition.
Once the partition is created, you have to format it:

newfs_msdos /dev/sdb1

Now edit the menu.lst file to add the parameter:

SDCARD=sdb1

Feedback on using Android_x86 vm as a testing environment

Usage

So far, the x86 VM works as expected and outside of the speed I did not notice any real difference.
All the Android projects have deployed correctly. Android API Sample project runs ok outside of the NDK.

The only visible point is that the Gallery app (Cooliris) is broken, I tested with a nightly build image, and it works a little bit better, but it’s still broken.

Another issue is that in about 10% of the cases, the VM does not boot and you have to reset the VM. Since boot is very fast this is not a pain, so I did not investigate further.

Speed

The difference in speed is really visible and significant.

 

Courtesy : http://www.nuxeo.com/blog/development/2011/10/speeding-up-the-android-emulator/

 

About these ads
Comments
  1. Andy Baker says:

    People reading this might get the impression they can’t run anything later than Android 2.3 in a VM so thought I’d link to this: http://androvm.org/blog/download/

  2. [...] it.  But then I found a 2nd tool that would bring speed to the table: VirtualBox.  I found a guide that walked me through setting up an x86 version of Android and configure it’s network [...]

  3. [...] How to speed up the Android Emulator by up to 400% (amitcs.wordpress.com) [...]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s