The Android Emulator is slow beyond belief. Over the 4-or-so years Android has been around it has only gotten worse, to the point of being something that will go down in the annals of Computer Science History. The fact that the vast majority of articles being published (today) about Android neglect to mention this all-too-painful fact is evidence that those articles are far from objective.
The goal of this post is to demonstrate how to get performance out of the emulator that won’t ‘kill’ you while developing and debugging. In fact, with the below recommendations, you might forget how slow the emulator once was. It might even be possible to develop an entire app on the emulator yet again (well, for the first time really, depending on your persepctive). Just imagine!
Now wake up. The Android Emulator is not a serious product for a professional Android developer, especially one who has an app to publish in Google Play. You need to purchase one or more Android devices for that type of development and testing. More can be said about this. In real-world usage your app will be on far more handsets than you can reasonably expect to source and purchase for testing. However, you also have constraints about what features are available for development and testing in the emulator. Ultimately you’ll have to find a balance for each Android project between how much time you spend using the emulator, versus how much on a device. More tools makes a happy engineer.
I’ve found these solid tricks to get the best performance out of the Android Emulator:
- Install a Solid State Drive (SSD). I witnessed this demo’ed for me two days ago and we tested the emulator. It made a massive difference in startup time! Improvement measured on order of 10.
- 16GB RAM. Again I just saw this demo’ed on a Mac. Huge difference in performance for the emulator. With 16GB it’s easier to roll with the emulator cached entirely in RAM without even trying.
- Reduce emulator screen size. When launching the emulator (manually) I’ll check the box “scale display” and use a scale-factor that gets the emulator to render about 50% of the original size. You may have to play around to get the right balance between speed and readability. This can be done by scaling DPI or entering a physical width/height when launching the emulator (or when configuring an AVD, or from the command line). It seems pretty clear that performance is directly impacted by the number of pixels the emulator is managing.
- Use virtual machine acceleration. This is a new feature as of SDK rev17. It also comes with at least a few caveats. http://developer.android.com/guide/developing/devices/emulator.html#accel-vm
- Perhaps you could use VirtualBox. An excellent tutorial is posted at http://dev.blogs.nuxeo.com/2011/10/speeding-up-the-android-emulator.html#comment-513787697. The caveat is: VirtualBox is an Android fork. It’s unreasonable to consider testing with VirtualBox to be a reliable reference, but that might be OK in some cases. Honestly, this seems to have potential, but after investigating the depth of forking and state of the VBox project I can’t recommend this as an option for professional developers. Even for beginners I’d think — you spend so much time getting that fork to run when you should be learning Android. So…use this at your own risk.
- Create AVDs with only the options you need for testing your app. Since creating AVDs is easy, create some with all options; and some with a very limited set that gets the job done for certain kinds of apps (or for a specific app). See http://developer.android.com/tools/devices/managing-avds.html
- Skip the boot animation. You can do this with the -no-boot-anim command line option. See http://developer.android.com/guide/developing/tools/emulator.html#startup-options for more.
- Enable startup snapshots. See http://tools.android.com/recent/emulatorsnapshots
- Set the emulator’s Cache partition (emulator option) to 64MB or greater. See
The top two solutions are the most effective. They can be summarized as: a heaping order of RAM with some SSD-RAM on top. Upgrading to 8-16 GB RAM (or more) and a solid-state-drive will get your dev environment running nice and fast (for everything, actually). Multiple CPU cores are a must – but there’s a good chance you already have that.
We can tinker with the emulator settings as described above all we want. If we only make those tweaks then we still get an emulator that kills hopes of rapid development! Another thing is, we can’t be limited to only one or two other apps running alongside the emulator. That’s the last thing we want when we’re trying to troubleshoot code.
What probably doesn’t work:
- Like I said – just tweaking the settings doesn’t work. It helps but you’ll still abandon the emulator whenever possible (i.e. use a real device).
- Buying a new computer (see http://stackoverflow.com/questions/2662650/making-the-android-emulator-run-faster/2662854). Nonono – that is not a solution. You will be happy with a new-fangled computer and it’ll run faster (at first), but the emulator will still kill your hopes of rapid development. Oh…you may get the sales person to let you install Android SDK and demo the emulator before you buy it. You might as well go and beg Murphy for help.
- 1GB RAM – not enough. 4GB RAM – probably not enough (unless emulator is the only app running). 8GB RAM – now you’re talking. Point is…we need the entire emulator to be executed in RAM, none in the virtual-ram or ram-disk.
- bug filed at http://code.google.com/p/android/issues/detail?id=26778. Vote for it. Tell ’em to build it natively. The imprvement in ADT17 (suggestion 7) is mentioned here.