Home > Blog > How to speed up the Android Emulator by up to 400%

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

I have been working on an Android SDK for the Nuxeo Content Management Platform in the past months (feel free to check out the early side of our developments in my previous blog post on that topic) and have worked more on it lately as we are on our way to making the first official release of this SDK. I wanted to share some feedback on a practical side of Android development related to test and emulation. After a few days of development, I found out that Android Emulator was a pain because it is far too slow.

First of all it is slow to boot, but even if you use Snapshot to speed up the start, the execution is also very slow, especially when using the debug mode.

Tweaking Qemu parameters did not help significantly, the emulator remains too slow, that’s probably why most Android developers seem to use a real device attached via USB.

Anyway, I wanted to find a solution, also because I want to be able to do a demonstration of an application via a beamer and don’t want to do the demonstration of a slow application.

Emulation vs. Simulation

I am not an Apple developer, but it looks like the iPhone simulator does not have the same issue as the Android Emulator.

One of the reasons for this is that it does not run a “real emulator”, because the CPU instruction used by the iPhone simulator is the same as the one used by the host (x86).

On the contrary, Android Emulator emulates a real ARM processor on top of an x86 processor. This is a lot of overhead.

At least for quick test and demonstration purposes, I don’t need to emulate an ARM processor, I just need to be able to run Android and my application.

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 setup 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.101

This 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 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 of speed is really visible and significant.

Here are some figures to give an idea of the speed improvements :




















































































QEmu + Android ARM (2.3.3) VirtualBox + Android X86 (2.3.5) Nexus One phone (2.3.6)

Result Speed ratio Result Speed ratio Result
Boot
(in seconds, lower is better)
55 109% 5 1200% 60
Android API GUI test
(in seconds, lower is better)
35 71% 20 125% 25
Android API OpenGL Sprite test
(in ms, lower is better)
65 28% 8 225% 18
BrowserMark
(index, higher is better)
5500 15% 165000 446% 37000
Nuxeo SDK test
(in seconds, lower is better)
26 58% 14 107% 15









43%
226%

Android ARM emulator is about half the speed of a Nexus One, whereas the Android x86 VM is about twice as fast.

img
img
img
img
Tagged : Mobile

71 thoughts on “How to speed up the Android Emulator by up to 400%

  1. Thanks for the information! Adding custom video modes to VirtualBox was what I was missing.
    Have you looked into getting higher color depth working?

  2. I cannot get the screen size as I want.
    I’ve followed all the steps, but always get a square screen
    any help?
    thanks

  3. thanks, it works for me :D (1000+ thump Article), but i want to mention for windows user, that for sample
    adb connect 192.168.54.101:5555
    that they must write the port (5555) to allow adb to connect

  4. The QEMU is so poor because you should be using kvm instead, and have a computer that support virtualization (Intel VT or AMD-V). Then you really will see some improvement!

  5. Android is the VM. If you install on your host then you will have Android phone pop up when you turn on your pc. Might be fun good office prank.

  6. Be sure to add the custom modes in VirtualBox and also check that your kernel parameters are ok.
    You can edit the kernel parameters from the bootloader menu and check that the changes in menu.lst were taken into account.
    During my tests, I had once the issue that the changes in the menu.lst were not saved for real : may be a sync issue when restarting too quickly after having edited the file.

  7. Doesn’t work like a dream any more. When I try to run my app, it crashes and the logcat goes:
    D/AndroidRuntime( 2016): >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
    D/AndroidRuntime( 2016): CheckJNI is ON
    D/AndroidRuntime( 2016): — registering native functions —
    I/ethernet( 2016): Loading ethernet jni class
    D/dalvikvm( 1522): GC_EXPLICIT freed 165 objects / 11808 bytes in 18ms
    D/PackageParser( 1212): Scanning package: /data/app/vmdl52064.tmp
    W/PackageParser( 1212): No actions in intent filter at /data/app/vmdl52064.tmp Binary XML file line #22
    I/PackageParser( 1212): com.——-: compat added android.permission.WRITE_EXTERNAL_STORAGE android.permission.READ_PHONE_STATE
    D/PackageManager( 1212): Scanning package com.antennasoftware.volt.storefront.android.ui
    I/PackageManager( 1212): /data/app/com.———1.apk changed; unpacking
    E/PackageManager( 1212): Package com.——- has mismatched uid: 10048 on disk, 10052 in settings
    W/PackageManager( 1212): Native ABI mismatch from package file
    W/PackageManager( 1212): Package couldn't be installed in /data/app/com.———1.apk
    D/dalvikvm( 1212): GC_EXPLICIT freed 5336 objects / 311640 bytes in 10ms

  8. Really interesting. Working on a toshiba satellite using the spartan release with Bridge networking.
    Cannot debug an application that uses the maps library from google:
    Installation error: INSTALL_FAILED_MISSING_SHARED_LIBRARY
    Any clue?
    Thanks

  9. I have tried Android x86, mostly out of curiosity, but I never thought of using it for development. I mean, isn’t being an emulator the whole point of the emulator?
    I like the fact that the emulator creates an ARM environment, and I know it will be slow. I pay that price for having as precise a reproduction as possible of the behavior in an actual device.

  10. IPhone simulator suffers with another issue. In fact, the simulator is running too fast, many problems cannot be discovered until the app goes into a real iPhone. So, we actually need something run as fast as the real device……

  11. Nice…
    One suggestion about connecting to ADB:
    Better use “NAT” network mode (default), which easily allows the device to connect to the internet.
    You then need to device (in VirtualBox Settings/Network) “port forwarding” from host:5555 to device 5555, and then “adb connect 127.0.0.1″ will connect the host to the device.

  12. Worked like a charm, and it is indeed super fast.
    I cannot use it though, since animations in jQuery mobile cause the Android browser to crash. You pretty much cannot to any page transitions without a browser crash.
    Anyone solved this problem?

  13. i got this ip from the virtual box preference because inside the android if i open
    the command line and type netcfg it give me this
    lo up 127.0.0.1 255.0.0.0 0x00000049

  14. Can you give me an example where you saw this? I do a lot of testing using the simulator and it would benefit me to know what to look for.
    thanks

  15. I can not setup the network correct, somehow android VM does not detect the VBox network interface.
    Does it sound like I am missing something ?

  16. there is a VBoxManage program in your VirtualBox directory. Goto the command prompt, goto vbox’s installation folder, and run the three commands mentioned.

  17. I’m having a problem creating the file-based SD Card. The line below is throwing a syntax error when trying to evaluate the text in parens:
    dd if=/dev/zero of=/data/sdcard.img bs=1024 count=65536 (64MB image)
    Is this command supposed to be entered exactly as shown? It seems like an SDCard directory is created, but the size is off and nothing can be copied to it.
    Has anyone gotten this to work?

  18. Does this only works for the version you used? Android 2.3 RC1? I followed your instructions but I used android 2.2.2 EEEPC. Everything went well, except that I can’t ping the host from the VM with android.

  19. I think it’s cool you’ve explored this.  Really cool.  Still, I’m measuring a 1-second operation on a Acer A100 tablet that takes over 40 seconds on the emulator.  If I apply your technique it goes down to maybe 10 seconds w/r/t the actual device.  10-to-1 is still unacceptable for me to be an efficient developer on the Android platform.  The iOS simulator is nearly 1:1.  It’s unfortunate.

  20. It seems to me they do not support ethernet for many android releases. At least I have started from the android ICS and could not connect via adb, then I was trying to use 
    Android-x86-2.3-RC1 I have connected successfully. See relaease notes, they support ethernet for this relaase only, hope they will fix this issue with later android relases. 

  21. Perfect. I’ll try it.
    But I wonder if I can integrate it with eclipse such as I compile it and run in emulator easily.
    Any suggestions?

  22. After investigating further and thinking about it more, this isn’t a reasonable solution for professional Android developers.  VBox is a deep Android fork and it’s unclear if it’s consistently maintained, and how far it’s devaited from official releases.  See my blog post at http://tenacious33.wordpress.com/2012/04/05/improving-android-emulator-performance/

  23. Everything works like a charm except:-
    when I type $adb devices on my MAC’s terminal…only a blank line is displayed. 

    netcfg on VirtualBox setting, displays IP address and port correctly.

    However when I try adb connect IP:port..
    unable to connect to IP:port

    when I type adb connect localhost:port…
    connected to 127.0.0.1:port.

    but no adb commands work.

    tried adb kill-server
    and adb start-server

    daemon is listening on 5037 port. etc.

    using:-
    android x86 2.2 generic.iso

    MAC laptop

    bridged connection (works inside the android emulator as well)

    Also tried checking the settings> applications> development> usb debugging.

    But no adb device is listed (I am supposing it should list some kind of an emulator)….

    Please Help. 

    thanks,

  24.  Works great, but I have a problem, sound is not working, I am using Sound Blaster 16 as the audio controller
    any idea?

  25. I’m using VMware. How can I create custom resolution modes like these virtualbox commands?
    VBoxManage setextradata “Android2.3″ “CustomVideoMode1″ “320x480x16″
    VBoxManage setextradata “Android2.3″ “CustomVideoMode2″ “640x960x16″
    VBoxManage setextradata “Android2.3″ “CustomVideoMode3″ “480x720x16″

  26. Well i too had problems with the emulator being so slow i started it at 512 ram size went too 600 faster but slower.. went too 700 and 800 so fast it wouldnt come on…   went too 400 then 300 ram size performance wise looks like i started up my phone …. But i finally but ram size too 250 and Bam the things runs like my phone at hand i would try 250 on ram size

  27. still cannot save menu.lst

    host: win7/win8
    what’s the (:wq) there man ? i even googled that with no good results !!
    help me save please ? :)) 

  28. * Power off the VM

    * Go to Settings > Network > Adapter 1

    * Tick “Enable Network Adapter”

    * “Attached to” => “NAT”

    * “Advanced > Adapter type” => “PCnet-FAST III …”

    * Click port forwarding

    * Set Name to whatever you want, Protocol to TCP, both host and guest ports to 5555

    Now you will be able to do this:

    > adb connect localhost #(or 127.0.0.1)

    and

    > adb shell

  29. Worked like a charm for me! I downloaded the 4.2-RC2 version and got it working in vbox on my Mac OSX 10.8.4 (Mountain Lion) without any problems.

    The JSON feed I tried to pull in in my app was taking forever in the standard Android emulator and now it takes about 1 second (270Kb online file).

    Very cewl article – THNX!

  30. to enter :wq, you have to click “Esc” to change to command line and then introduce :wq and press ENTER, that will save the file

  31. It’s better to simply use a real device, it’s much more performent, even with a further 400% speed.

  32. naturally i restored any of them since a past computer system board. there may be mainly a huge amount 6v3 capacitors can be found on all these message boards. because the elegant legs of the aforementioned second handers have been completely short, I were required to extend these kind of people simply 3 cm concerning lower-calf with a couple wire I had laying around in.

  33. I just want to tell you that I am just newbie to blogging and site-building and seriously liked this website. Likely I’m want to bookmark your website . You actually have fantastic well written articles. Thanks a lot for sharing your blog.

  34. hello there and thank you for your information – I have definitely picked
    up anything new from right here. I did however expertise
    some technical issues using this website, since I experienced to
    reload the web site a lot of times previous to I could
    get it to load properly. I had been wondering if your hosting is OK?
    Not that I’m complaining, but slow loading instances times will often affect your placement in google and could damage your
    quality score if ads and marketing with Adwords. Well I am adding this RSS to my e-mail and can look out for a
    lot more of your respective exciting content. Ensure that
    you update this again very soon.

  35. uncover deer as well as turkeys in the area. i would say the parcel used to participate in an increased farmville farm. in half of that is a maple hardwood hardwoods, that wasthat’s make a decision slice many years ago. micheal O’Neill maintains outlined Pakistan seeming to be the 18th broadest current economic conditions in today’s world by just 2050. brand-new areas such as coined businesses BRIC (brazil, italy, asia, tiongkok) In 2000 and here brand-new areas such as given mint (south america, indonesia, Nigeria, turkey), appearing to be superior grinders ever financial climate. in this man’s calculation, Pakistan has the possibility to come out as the 18th chief economic conditions in this field after 2050,

  36. methods in a front door hot it down at last with all the early new york music group pink devastate, who exactly provided by a quick and forceful set up that has been along with the passionate boundaries of interior and the thrill noticed that you build throughout the lump crowd. “improved In town” so “Shiftless during bored” Both was rowdy as live at a homes where the ‘Mats first distributed his or phrase, and so the located closed up and a vehement accept the song you choose gives your blog it’s actually legal name. it brought in “Gimme seem” just mentioning, “simply the song we know a minimum, also it’s probably punk steel, and also the surfacing people achieved it rights by having unruly edition as the viewers answered in price,

  37. I simply want to say I am new to blogging and site-building and certainly enjoyed this website. Very likely I’m planning to bookmark your site . You amazingly have good stories. Kudos for revealing your website.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>