The Android SDK includes a virtual mobile device emulator that runs on your computer. The emulator lets you prototype, develop and test Android applications without using a physical device. The Android emulator mimics all of the hardware and software features of a typical mobile device, except that it cannot place actual phone calls. Here is guide on how to run Android emulator on Linux System.
- Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit)
- Mac OS X 10.5.8 or later (x86 only)
- Linux (tested on Ubuntu Linux, Lucid Lynx)
- GNU C Library (glibc) 2.7 or later is required.
- On Ubuntu Linux, version 8.04 or later is required.
- 64-bit distributions must be capable of running 32-bit applications.
Other development environments
- JDK 6 (JRE alone is not sufficient)
- Apache Ant 1.8 or later
- Not compatible with Gnu Compiler for Java (gcj)
Now, let’s start!
To install Java JDK
On Ubuntu, Debian System:
# apt-get install openjdk-7-jdk
On Arch Linux
# pacman -S jdk7-openjdk
To install Java JDK on CentOS, Fedora or RHEL, first set up Repoforge repository on your system, and then run the following.
# yum install java-1.7.0-openjdk-devel
Install addition requirements
For 64-bit Linux user: you must install another prerequisite called
ia32-libs since Android emulator is 32-bit software. The
ia32-libs package contains a set of runtime libraries for the ia32/i386 architecture, configured for use on a 64-bit kernel. On 64-bit Linux, the
mksdcard utility which creates SD cards will fail without this package.
# apt-get install ia32-libs
While using ia32-libs, if you encounter any error with 32-bit libGL.so, do the following:
# ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1.2.0 /usr/lib/libGL.so
Install Android SDK ADT
Download Android SDK ADT bundle from Android official site. Unzip the downloaded file then copy the sdk directory to your preferred location. I assume that the installation directory of Android SDK is ~/android-sdks.
Start your first Android Emulator
In order to run Android emulator, you first need to create a new AVD (Android Virtual Device) which is an emulator configuration for the Android device to be emulated. To create a new AVD, first launch Android SDK Manager by running the following.
Tools > Manage AVDs on Android SDK Manager’s menu. It will open up AVD Manager. Click on Add button to create a new AVD.
You can check the list of available Android Virtual Device as follows.
$ ~/android-sdk/android list avds
Available Android Virtual Devices:
Target: Android 4.2 (API level 17)
Booting up Android emulator may be slow (even taking minutes) depending on your hardware. Once Android emulator is successfully launched, you will see an running instance of Android device.
Installing Applications on the Emulator
If you don’t have access to Eclipse or the ADT Plugin, you can install your application on the emulator using the adb utility. Before installing the application, you need to build and package it into an .apk as described in Building and Running Apps. Once the application is installed, you can start the emulator from the command line as described previously, using any startup options necessary. When the emulator is running, you can also connect to the emulator instance’s console to issue commands as needed.
SD Card Emulation
You can create a disk image and then load it to the emulator at startup, to simulate the presence of a user’s SD card in the device. To do this, you can specify an SD card image when you create an AVD, or you can use the mksdcard utility included in the SDK.
There are several ways of creating an SD card image. The easiest way is to use the AVD Manager to create a new SD card by specifying a size when you create an AVD. You can also use the
android command line tool when creating an AVD. Just add the
-c option to your command:
$ ~/android-sdk/android create avd -n <avd_name> -t -c [K|M]
Making the Android emulator run faster
o make the emulator faster, you have to give it more CPU. Start with a fast CPU or upgrade if you can.
Then, give the emulator more of the CPU you have:
- Disable Hyperthreading – Since the emulator doesn’t appear to utilize more than one core, hyperthreading actually reduces the amount of overall CPU time the emulator will get. Disabling HT will slow down apps that take advantage of multiple CPUs. Hyperthreading must be disabled in your BIOS.
- Make the emulator run on a CPU other than CPU 0 – This has a much smaller impact than turning off HT, but it helps some. On Windows, you can specify which CPU a process will run on. Many apps will chew up CPU 0, and by default the emulator runs on CPU 0. I change the emulator to run on the last one. Note that on OS X you cannot set affinity.
- Enable GPU Hardware Acceleration (in addition to Intel’s HAXM), if you are using API 15 v3 or newer and SDK Tools v17+. Graphics acceleration for the emulator takes advantage of your development computer’s graphics hardware, specifically its graphics processing unit (GPU), to make screen drawing faster. This gives a noticeable boost in speed.To enable graphics acceleration enabled by default on your emulator: when creating the AVD, in the Hardware section, click New, select GPU emulation and set the value to Yes.
To enable acceleration only at runtime: use the -gpu flag while starting the emulator like this:
emulator -avd <avd_name> -gpu on
I’m seeing somewhere around a 50% improvement with these two changes in place.