Speed-up your Android Emulator in Linux

2014, Feb 16    

          As Android ecosystem becomes the Largest Mobile Platform, many developers want to put their legs in this ecosystem. Android ecosystem gives its users a large variety of devices powered with different specs. This become headache for almost all Android developers in testing their application while developing and make sure that it will work proper in wide range of devices. So to do this, developers create different emulators with different specs and run their app. But are they happy with it?  I guess, No. Because the performance of Android Emulator is very slow, and if the application is doing some major works like server communication, animations, etc, then emulator sucks like anything.

          This post focuses on speeding up your Android Emulator, so that it will run as fast as the real device.

This Post Is For

          Are you an Android Developer?
          Are you developing your applications in Linux platform?
          Is your emulator performance is very slow?

          Those who has the answer Yes for all the above questions can get a solution from this post.

How To Achieve This?

          To achieve this you just need to configure your Emulator with some specific Android System Images and Hardware Drivers and let it take the advantage of Hardware Acceleration.

          You can make your Emulator take the advantage of Hardware Acceleration in the following ways:
  • By configuring it with Graphics Acceleration
  • By configuring it with Virtual Machine Acceleration

Configuring Emulator With Graphics Acceleration:

          Graphics Accelerated Emulators wil take the advantage of the systems's Graphics Processing Unit (GPU) to make the Emulator run faster and more responsive.

NOTE: This will only work if your PC has GPU. Otherwise instead of increasing the performance, it may decrease it.

Prerequisites:

          You need to install the following two things through Android SDK Manager: 
  • Android SDK Tools, Revision 17 or higher
  • Android SDK Platform API 15, Revision 3 or higher (Android 4.0.3 or higher)
          Are you running your emulator through command line? Type the following command to start an emulator:


<avd_name>
NOTE: The <avd_name> should be the name of any AVD which has the Target more than Android 4.0.3.

          Are you running emulator through eclipse? Follow the below steps:

  1. Right click on your project folder, Go to Run As > Run Configurations...
  2. Click on Android Application > New_configuration.
  3. Click the Target tab.
  4. Select an AVD with Android 4.0.3 or higher.
  5. In the Additional Emulator Command Line Options field, enter: -gpu on
  6. Run your application using this Run Configuration.
          Instead of setting the Run Configuration each time you run your application, if you want to configure it once and use it for all time, then follow the below steps:
  1. Create a new AVD with Target as Android 4.0.3 or higher.
  2. In the Hardware selection, click New and select the option GPU emulation and set the value to yes.
  3. Click Create AVD. And you are done.
          Now you can use this AVD to run your application any number of time. Below is the sample screenshot of this:


Configuring Emulator With Virtual Machine Acceleration:

          Before doing anything you should first know whether your PC supports any of the following virtualization technologies or not.
  1. Intel Virtualization Technology (VT, VT-x, vmx) extensions.
  2. AMD Virtualization (AMD-V, SVM) extensions.
          To know whether your PC supports any of the above virtualization technologies, use the following command in the terminal:



          The output of the following command will be an integer value. If the value is:

  • 0 - Means your PC does not supports hardware virtualization. So you cannot use VM Acceleration for your emulator. You have to be satisfied with GPU Emulation explained above.
  • 1 or more - Yes, your PC supports hardware virtualization. So you can proceed with the below steps.

Prerequisites:

          You got confirmed that your PC supports hardware virtualization. so before proceeding further install the following two things through Android SDK Manager: 
  • Android SDK Tools, Revision 17 or higher
  • Android x-86 based System Image
  • Create an AVD with the above two things.
          Linux based OS supports hardware virtualization through a software package called Kernel-based Virtual Machine (KVM). So your next step is to install KVM on your PC.

Installing Kernel-based Virtual Machine (KVM):

          Open your Terminal and execute


          You might get any of the following results:



          Congrats, your PC is ready to use hardware virualization. you just need to install KVM and use it.



          You just Shut Down your PC and next time when you starts, just go to BIOS Setup  and enable the virtualization. After enabling it you can go forward to install KVM and use it. The following screenshot may help you a bit on enabling the virtualization in BIOS.


          Now start installing the KVM package using the following command in terminal:



          After the installation successfully completes, add your user name to the following groups:



          You are almost done. Now you just need to restart your PC to make these changes be affected. But before going to any further steps lets verify whether your installation was successful or not.

Verifying KVM Installation:

          In the terminal, execute:



          Are you getting an output like below? Then your installation was right.



          You may also get an output something like this, then something is wrong. You need to fix this before you move on.



Almost Done:

          After installation of KVM succeed, you just need to make it used by Emulator. So lets do that.
  1. If you are running the emulator through command line, then execute the command as below:

  2. If you are running the emulator using eclipse, then follow the below steps:
    1. Right click on your project folder, then go to RunAs > Run Configurations...
    2. On the Run Configurations, select your project configuration or create a new configuration.
    3. Click the Target tab.
    4. Select an AVD associated with any x-86 based system image.
    5. In the Additional Emulator Command Line Options field, type:

References:

          Installing KVM
          Using Android Emulator

Conclusion:

          After following the above mentioned step, your Emulator will run faster like Usain Bolt and more responsive.The only thing is, you just need to configure the install the KVM properly and the AVD configurations should be proper as per the instructions.