Emulator PDF
Emulator PDF
In this document 1. 2. 3. 4. 5. Overview Android Virtual Devices and the Emulator Starting and Stopping the Emulator Installing Applications on the Emulator Using Hardware Acceleration 1. Configuring Graphics Acceleration 2. Configuring Virtual Machine Acceleration 6. SD Card Emulation 1. Creating an SD card image 2. Copying files to an SD card image 3. Loading an SD card image 7. Working with Emulator Disk Images 1. Default image files 2. Runtime images: user data and SD card 3. Temporary images 8. Emulator Networking 1. Network Address Space 2. Local Networking Limitations 3. Using Network Redirection 4. Configuring the Emulator's DNS Settings 5. Using the Emulator with a Proxy 6. Interconnecting Emulator Instances 7. Sending a Voice Call or SMS to Another Emulator Instance 9. Using the Emulator Console 1. Port Redirection 2. Geo Location Provider Emulation 3. Hardware Events Emulation 4. Device Power Characteristics 5. Network Status 6. Network Delay Emulation 7. Network Speed Emulation 8. Telephony Emulation 9. SMS Emulation 10.VM State 11.Emulator Window 12.Terminating an Emulator Instance 10.Emulator Limitations 11.Troubleshooting Emulator Problems
See also
1. Android Emulator 2. Managing AVDs with AVD Manager 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. It provides a variety of navigation and control keys, which you can "press" using your mouse or keyboard to generate events for your application. It also
provides a screen in which your application is displayed, together with any other active Android applications.
To let you model and test your application more easily, the emulator utilizes Android Virtual Device (AVD) configurations. AVDs let you define certain hardware aspects of your emulated phone and allow you to create many configurations to test many Android platforms and hardware permutations. Once your application is running on the emulator, it can use the services of the Android platform to invoke other applications, access the network, play audio and video, store and retrieve data, notify the user, and render graphical transitions and themes. The emulator also includes a variety of debug capabilities, such as a console from which you can log kernel output, simulate application interrupts (such as arriving SMS messages or phone calls), and simulate latency effects and dropouts on the data network.
Overview
The Android emulator is an application that provides a virtual mobile device on which you can run your Android applications. It runs a full Android system stack, down to the kernel level, that includes a set of preinstalled applications (such as the dialer) that you can access from your applications. You can choose what version of the Android system you want to run in the emulator by configuring AVDs, and you can also customize the mobile device skin and key mappings. When launching the emulator and at runtime, you can use a variety of commands and options to control its behavior. The Android system images available through the Android SDK Manager contain code for the Android Linux kernel, the native libraries, the Dalvik VM, and the various Android packages (such as the Android framework and preinstalled applications). The emulator provides dynamic binary translation of device machine code to the OS and processor architecture of your development machine. The Android emulator supports many hardware features likely to be found on mobile devices, including: An ARMv5 CPU and the corresponding memory-management unit (MMU) A 16-bit LCD display One or more keyboards (a Qwerty-based keyboard and associated Dpad/Phone buttons) A sound chip with output and input capabilities Flash memory partitions (emulated through disk image files on the development machine) A GSM modem, including a simulated SIM Card A camera, using a webcam connected to your development computer. Sensors like an accelerometer, using data from a USB-connected Android device.
The following sections describe the emulator and its use for development of Android applications in more detail.
This initializes the emulator, loads an AVD configuration and displays the emulator window. For more information about command line options for the emulator, see the Android Emulator tool reference. Note: You can run multiple instances of the emulator concurrently, each with its own AVD configuration and storage area for user data, SD card, and so on. If you are working in Eclipse, the ADT plugin for Eclipse installs your application and starts the emulator automatically, when you run or debug the application. You can specify emulator startup options in the Run/Debug dialog, in the Target tab. When the emulator is running, you can issue console commands as described later in this document. If you are not working in Eclipse, see Installing Applications on the Emulator for information about how to install your application. To stop an emulator instance, just close the emulator's window. For a reference of the emulator's startup commands and keyboard mapping, see the Android Emulator tool reference.
the application runs properly as you update it, you may need to delete the emulator's user-data partition. To do so, start the emulator with the -wipe-data option. For more information about the user-data partition and other emulator storage, see Working with Emulator Disk Images.
Note: You must specify an AVD configuration that uses Android 4.0.3 (API Level 15, revision 3) or higher system image target. Graphics acceleration is not available for earlier system images. If you are running the emulator from Eclipse, run your Android application using an AVD with the -gpu on option enabled: 1. In Eclipse, click your Android project folder and then select Run > Run
Configurations... 2. In the left panel of the Run Configurations dialog, select your Android project run configuration or create a new configuration. 3. Click the Target tab. 4. Select the AVD you created in the previous procedure. 5. In the Additional Emulator Command Line Options field, enter: -gpu on 6. Run your Android project using this run configuration.
image may not be available for all API levels. 2. Start the AVD Manager and create a new AVD with an x86 value for the CPU/ABI field. You may need to select a specific Target value, or select a Target value and then select a specific CPU/ABI option. 3. Name the emulator instance and select any other configuration options. 4. Click Create AVD to save the emulator configuration. Configuring VM Acceleration on Windows Virtual machine acceleration for Windows requires the installation of the Intel Hardware Accelerated Execution Manager (Intel HAXM). The software requires an Intel CPU with Virtualization Technology (VT) support and one of the following operating systems: Windows 7 (32/64-bit) Windows Vista (32/64-bit) Windows XP (32-bit only) To install the virtualization driver: 1. Start the Android SDK Manager, select Extras and then select Intel Hardware Accelerated Execution Manager. 2. After the download completes, execute <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/Intel HAXM.exe. 3. Follow the on-screen instructions to complete installation. 4. After installation completes, confirm that the virtualization driver is operating correctly by opening a command prompt window and running the following command:
sc query intelhaxm
: 4
RUNNING
To run an x86-based emulator with VM acceleration: If you are running the emulator from the command line, just specify an x86-based AVD:
emulator -avd <avd_name>
Note: You must provide an x86-based AVD configuration name, otherwise VM acceleration will not be enabled. If you are running the emulator from Eclipse, run your Android application with an x86-based AVD: 1. In Eclipse, click your Android project folder and then select Run > Run Configurations... 2. In the left panel of the Run Configurations dialog, select your Android project run configuration or create a new configuration. 3. Click the Target tab. 4. Select the x86-based AVD you created previously. 5. Run your Android project using this run configuration. You can adjust the amount of memory available to the Intel HAXM kernel extension by re-running its installer.
You can stop using the virtualization driver by uninstalling it. Re-run the installer or use the Control Panel to remove the software. Configuring VM Acceleration on Mac Virtual machine acceleration on a Mac requires the installation of the Intel Hardware Accelerated Execution Manager (Intel HAXM) kernel extension to allow the Android emulator to make use of CPU virtualization extensions. The kernel extension is compatible with Mac OS X Snow Leopard (version 10.6.0) and higher. To install the Intel HAXM kernel extension: 1. Start the Android SDK Manager, select Extras and then select Intel Hardware Accelerated Execution Manager. 2. After the download completes, execute <sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/Intel HAXM.dmg. 3. Double click the IntelHAXM.mpkg icon to begin installation. 4. Follow the on-screen instructions to complete installation. 5. After installation completes, confirm that the new kernel extension is operating correctly by opening a terminal window and running the following command:
kextstat | grep intel
You should see a status message containing the following extension name, indicating that the kernel extension is loaded:
com.intel.kext.intelhaxm
To run an x86-based emulator with VM acceleration: If you are running the emulator from the command line, just specify an x86-based AVD:
emulator -avd <avd_name>
Note: You must provide an x86-based AVD configuration name, otherwise VM acceleration will not be enabled. If you are running the emulator from Eclipse, run your Android application with an x86-based AVD: 1. In Eclipse, click your Android project folder and then select Run > Run Configurations... 2. In the left panel of the Run Configurations dialog, select your Android project run configuration or create a new configuration. 3. Click the Target tab. 4. Select the x86-based AVD you created previously. 5. Run your Android project using this run configuration. You can adjust the amount of memory available to the Intel HAXM kernel extension by re-running the installer. You can stop using the virtualization kernel driver by uninstalling it. Before removing it, shut down any running x86 emulators. To unload the virtualization kernel driver, run the following command in a terminal window:
sudo /System/Library/Extensions/intelhaxm.kext/Contents/Resources/uninstall.sh
Configuring VM Acceleration on Linux Linux-based systems support virtual machine acceleration through the KVM software package.
Follow instructions for installing KVM on your Linux system, and verify that KVM is enabled. In addition to following the installation instructions, be aware of these configuration requirements: Running KVM requires specific user permissions, make sure you have sufficient permissions according to the KVM installation instructions. If you use another virtualization technology in your Linux platform, unload its kernel driver before running the x86 emulator. For example, the VirtualBox driver program is vboxdrv. To run an x86-based emulator with VM acceleration: If you are running the emulator from the command line, start the emulator with an x86-based AVD and include the KVM options:
emulator -avd <avd_name> -qemu -m 512 -enable-kvm
Note: You must provide an x86-based AVD configuration name, otherwise VM acceleration will not be enabled. If you are running the emulator from Eclipse, run your Android application with an x86-based AVD and include the KVM options: 1. In Eclipse, click your Android project folder and then select Run > Run Configurations... 2. In the left panel of the Run Configurations dialog, select your Android project run configuration or create a new configuration. 3. Click the Target tab. 4. Select the x86-based AVD you created previously. 5. In the Additional Emulator Command Line Options field, enter:
-qemu -m 512 -enable-kvm
6. Run your Android project using this run configuration. Important: When using the -qemu command line option, make sure it is the last parameter in your command. All subsequent options are interpreted as qemu-specific parameters.
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. The following sections describe how to create an SD card disk image, how to copy files to it, and how to load it in the emulator at startup. Note that you can only load a disk image at emulator startup. Similarly, you can not remove a simulated SD card from a running emulator. However, you can browse, send files to, and copy/remove files from a simulated SD card either with adb or the emulator. The emulator supports emulated SDHC cards, so you can create an SD card image of any size up to 128 gigabytes.
The -c option can also be used to to specify a path to an SD card image for the new AVD. For more information, see Managing Virtual Devices from the Command Line.
You can also use the mksdcard tool, included in the SDK, to create a FAT32 disk image that you can load in the emulator at startup. You can access mksdcard in the tools/ directory of the SDK and create a disk image like this:
mksdcard <size> <file>
For example:
mksdcard 1024M sdcard1.iso
The emulator provides the -system <dir> startup option to let you override the location where the emulator looks for the default user data image. The emulator also provides a startup option that lets you override the name of the default user data image, as described in the following table. When you use the option, the emulator looks in the default directory, or in a custom location (if you specified -system <dir>). Name Description Comments Override using -initdata <file>. Also see -data <file>, below.
userdata-qemu.img
sdcard.img
User-Data Image Each emulator instance uses a writeable user-data image to store user- and session-specific data. For example, it uses the image to store a unique user's installed application data, settings, databases, and files. At startup, the emulator attempts to load a user-data image stored during a previous session. It looks for the file in the current working directory, in the AVD directory described in a previous section and at the custom location/name that you specified at startup. If it finds a user-data image, it mounts the image and makes it available to the system for reading and writing of user data.
If it does not find one, it creates an image by copying the system user-data image (userdata.img), described above. At device power-off, the system persists the user data to the image, so that it will be available in the next session. Note that the emulator stores the new disk image at the location/name that you specify in -data startup option. Note: Because of the AVD configurations used in the emulator, each emulator instance gets its own dedicated storage. There is no longer a need to use the -d option to specify an instance-specific storage area. SD Card Optionally, you can create a writeable disk image that the emulator can use to simulate removeable storage in an actual device. For information about how to create an emulated SD card and load it in the emulator, see SD Card Emulation You can also use the android tool to automatically create an SD Card image for you, when creating an AVD. For more information, see Managing Virtual Devices with AVD Manager.
Temporary Images
The emulator creates two writeable images at startup that it deletes at device power-off. The images are: A writable copy of the Android system image The /cache partition image The emulator does not permit renaming the temporary system image or persisting it at device poweroff. The /cache partition image is initially empty, and is used by the browser to cache downloaded web pages and images. The emulator provides an -cache <file>, which specifies the name of the file in which to persist the /cache image at device power-off. If <file> does not exist, the emulator creates it as an empty file. You can also disable the use of the cache partition by specifying the -nocache option at startup.
Emulator Networking
The emulator provides versatile networking capabilities that you can use to set up complex modeling and testing environments for your application. The sections below introduce the emulator's network architecture and capabilities.
10.0.2.6 10.0.2.15 The emulated device's own network/ethernet interface 127.0.0.1 The emulated device's own loopback interface Note that the same address assignments are used by all running emulator instances. That means that if you have two instances running concurrently on your machine, each will have its own router and, behind that, each will have an IP address of 10.0.2.15. The instances are isolated by a router and can not see each other on the same network. For information about how to let emulator instances communicate over TCP/UDP, see Connecting Emulator Instances. Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you want to access services running on your development machine's loopback interface (a.k.a. 127.0.0.1 on your machine), you should use the special address 10.0.2.2 instead. Finally, note that each emulated device's pre-allocated addresses are specific to the Android emulator and will probably be very different on real devices (which are also very likely to be NAT-ed, i.e., behind a router/firewall)
Once connected, use the redir command to work with redirection. To add a redirection, use:
add <protocol>:<host-port>:<guest-port>
where <protocol> is either tcp or udp, and <host-port> and <guest-port> sets the mapping between your own machine and the emulated system, respectively. For example, the following command sets up a redirection that handles all incoming TCP connections to your host (development) machine on 127.0.0.1:5000 and will pass them through to the emulated system's 10.0.2.15:6000.:
redir add tcp:5000:6000
To delete a redirection, you can use the redir del command. To list all redirection for a specific instance, you can use redir list. For more information about these and other console commands, see Using the Emulator Console. Note that port numbers are restricted by your local environment. this typically means that you cannot use host port numbers under 1024 without special administrator privileges. Also, you won't be able to set up a redirection for a host port that is already in use by another process on your machine. In that case, redir generates an error message to that effect. Setting Up Redirection through ADB The Android Debug Bridge (ADB) tool provides port forwarding, an alternate way for you to set up network redirection. For more information, see Forwarding Ports in the ADB documentation. Note that ADB does not currently offer any way to remove a redirection, except by killing the ADB server.
or
http://<username>:<password>@<machineName>:<port>
The -http-proxy option forces the emulator to use the specified HTTP/HTTPS proxy for all
outgoing TCP connections. Redirection for UDP is not currently supported. Alternatively, you can define the environment variable http_proxy to the value you want to use for <proxy>. In this case, you do not need to specify a value for <proxy> in the -http-proxy command the emulator checks the value of the http_proxy environment variable at startup and uses its value automatically, if defined. You can use the -verbose-proxy option to diagnose proxy connection problems.
To connect to the console of any running emulator instance at any time, use this command:
telnet localhost <console-port>
An emulator instance occupies a pair of adjacent ports: a console port and an adb port. The port numbers differ by 1, with the adb port having the higher port number. The console of the first emulator instance running on a given machine uses console port 5554 and adb port 5555. Subsequent instances use port numbers increasing by two for example, 5556/5557, 5558/5559, and so on. Up to 16 concurrent emulator instances can run a console facility. To connect to the emulator console, you must specify a valid console port. If multiple emulator instances are running, you need to determine the console port of the emulator instance you want to connect to. You can find the instance's console port listed in the title of the instance window. For example, here's the window title for an instance whose console port is 5554: Android Emulator (5554) Alternatively, you can use the adb devices command, which prints a list of running emulator instances and their console port numbers. For more information, see Querying for Emulator/Device Instances in the adb documentation. Note: The emulator listens for connections on ports 5554-5587 and accepts connections only from localhost. Once you are connected to the console, you can then enter help [command] to see a list of console commands and learn about specific commands. To exit the console session, use quit or exit. The following sections below describe the major functional areas of the console.
Port Redirection
You can use the console to add and remove port redirection while the emulator is running. After you connect to the console, manage port redirection by entering the following command:
redir <list|add|del>
The redir command supports the subcommands listed in the table below. Subcommand list Description List the current port redirection. Comments
<protocol> must be either "tcp" or "udp" <host-port> is the port number to open on the host <guest-port> is the port number to route data to on the emulator/device The meanings of <protocol> and <host-port> are listed in the previous row.
geo <fix|nmea>
The geo command supports the subcommands listed in the table below. Comments Specify longitude and latitude in Send a simple GPS fix to the decimal degrees. Specify altitude in emulator instance. meters. Send an NMEA 0183 sentence <sentence> must begin with to the emulated device, as if it '$GP'. Only '$GPGGA' and nmea <sentence> were sent from an emulated '$GPRCM' sentences are currently GPS modem. supported. You can issue the geo command as soon as an emulator instance is running. The emulator sets the location you enter by creating a mock location provider. This provider responds to location listeners set by applications, and also supplies the location to the LocationManager. Any application can query the location manager to obtain the current GPS fix for the emulated device by calling:
LocationManager.getLastKnownLocation("gps")
Description
The event command supports the subcommands listed in the table below. Subcommand Description Comments send Send one or more events to the You can use text names or integers <type>:<code>:<valu for <type> and <value>. Android kernel. e> [...] List all <type> string aliases types supported by the event subcommands. List all <codes> string aliases supported by the event codes <type> subcommands for the specified <type>. The message must be a UTF-8 string. Simulate keypresses to send the Unicode posts will be reverseevent text specified string of characters as a mapped according to the current <message> message, device keyboard. Unsupported characters will be discarded silently.
The event command supports the subcommands listed in the table below. Subcommand Description Comments
display ac <on|off> status <unknown| charging|discharging| not-charging|full> present <true|false> health <unknown|good| overheat|dead| overvoltage|failure> power health <percent>
Display battery and charger state. Set AC charging state to on or off. Change battery status as specified. Set battery presence state. Set battery health state. Set remaining battery capacity state (0-100).
Network Status
You can use the console to check the network status and current delay and speed characteristics. To do so, connect to the console and use the netstatus command. Here's an example of the command and its output.
network status
To make changes to network delay while the emulator is running, connect to the console and use the netdelay command with a supported <delay> value from the table below.
network delay gprs
The format of network <delay> is one of the following (numbers are milliseconds): Value gprs edge umts none <num> <min>:<max> Description GPRS EDGE/EGPRS UMTS/3G No latency Emulate an exact latency (milliseconds). Emulate an specified latency range (min, max milliseconds). Comments (min 150, max 550) (min 80, max 400) (min 35, max 200) (min 0, max 0)
the emulator. To set the network speed at emulator startup, use the -netspeed emulator option with a supported <speed> value, as listed in the table below. Here are some examples:
emulator -netspeed gsm emulator -netspeed 14.4 80
To make changes to network speed while the emulator is running, connect to the console and use the netspeed command with a supported <speed> value from the table below.
network speed 14.4 80
The format of network <speed> is one of the following (numbers are kilobits/sec): Value gsm hscsd gprs edge umts hsdpa full <num> <up>:<down> Description GSM/CSD HSCSD GPRS EDGE/EGPRS UMTS/3G HSDPA no limit Set an exact rate used for both upload and download. Set exact rates for upload and download separately. Comments (Up: 14.4, down: 14.4) (Up: 14.4, down: 43.2) (Up: 40.0, down: 80.0) (Up: 118.4, down: 236.8) (Up: 128.0, down: 1920.0) (Up: 348.0, down: 14400.0) (Up: 0.0, down: 0.0)
Telephony Emulation
The Android emulator includes its own GSM emulated modem that lets you simulate telephony functions in the emulator. For example, you can simulate inbound phone calls, establish data connections and terminate them. The Android system handles simulated calls exactly as it would actual calls. The emulator does not support call audio. You can use the gsm command to access the emulator's telephony functions after connecting to the console. The syntax for this command is as follows:
gsm <call|accept|busy|cancel|data|hold|list|voice|status>
The gsm command supports the subcommands listed in the table below. Subcommand call <phonenumber> accept <phonenumber> Description Simulate an inbound phone call from <phonenumber>. Accept an inbound call from <phonenumber> and change the call's state "active". Close an outbound call to <phonenumber> and change the call's state to "busy". Terminate an inbound or outbound phone call Comments
You can change a call's state to "active" only if its current state is "waiting" or "held".
You can change a call's state to "busy" only if its current state is "waiting".
to/from <phonenumber>. Supported <state> values are: unregistered -- No network available home -- On local network, non-roaming roaming -- On roaming network searching -- Searching networks denied -- Emergency calls only off -- Same as 'unregistered' on -- same as 'home'
data <state>
hold list
Change the state of a call You can change a call's state to "held" only if its to "held". current state is "active" or "waiting". List all inbound and outbound calls and their states. Supported <state> values are: unregistered -- No network available home -- On local network, non-roaming roaming -- On roaming network searching -- Searching networks denied -- Emergency calls only off -- Same as 'unregistered' on -- Same as 'home' Values are those described for the voice and data commands.
voice <state>
status
SMS Emulation
The Android emulator console lets you generate an SMS message and direct it to an emulator instance. Once you connect to an emulator instance, you can generate an emulated incoming SMS using the following command:
sms send <senderPhoneNumber> <textmessage>
where <senderPhoneNumber> contains an arbitrary numeric string. The console forwards the SMS message to the Android framework, which passes it through to an application that handles that message type.
VM State
You can use the vm command to control the VM on an emulator instance. The syntax for this command is as follows:
vm <start|stop|status>
The vm command supports the subcommands listed in the table below. Subcommand Description Comments
Start the VM on the instance. Stop the VM on the instance. Display the current status of the VM (running or stopped).
Emulator Window
You can use the window command to manage the emulator window. The syntax for this command is as follows:
window <scale>
The vm command supports the subcommands listed in the table below. Subcommand Description Comments A number between 0.1 and 3 that sets the scaling factor. You can also specify scale as a DPI value if you add the suffix "dpi" to the scale value. A value of "auto" tells the emulator to select the best window size.
scale <scale>
Emulator Limitations
The functional limitations of the emulator include: No support for placing or receiving actual phone calls. You can simulate phone calls (placed and received) through the emulator console, however. No support for USB connections No support for device-attached headphones No support for determining network connected state No support for determining battery charge level and AC charging state No support for determining SD card insert/eject No support for Bluetooth