Aug 28, 2021 Android Emulator For Mac Os X Yosemite The emulator suite also allows installed Android applications to use hardware like microphones and cameras if required. In addition, with applications that require strong graphics capabilities, BlueStacks can also respond by optimizing hardware on Mac computers. Aug 24, 2021 An Android emulator is a software application that allows your mobile to imitate Android OS. Aug 19, 2021 Since this is a full Android emulator, you can also reposition the apps on the home screen and install widgets just like you can on a real Android device. Andy works on not only Windows 10 but also Windows 8 and Windows 7, plus Ubuntu 14.04+ and Mac OS X 10.8+.
In this document
- Using Hardware Acceleration
- SD Card Emulation
- Working with Emulator Disk Images
- Emulator Networking
- Using the Emulator Console
See also
The Android SDK includes a virtual mobile device emulatorthat runs on your computer. The emulator lets you prototype, develop and testAndroid applications without using a physical device.
The Android emulator mimics all of the hardware and software featuresof a typical mobile device, except that it cannot place actual phonecalls. 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 alsoprovides a screen in which your application is displayed, together with any otheractive Android applications.
To let you model and test your application more easily, the emulator utilizesAndroid Virtual Device (AVD) configurations. AVDs let you define certain hardwareaspects of your emulated phone and allow you to create many configurations to testmany Android platforms and hardware permutations. Once your application is running onthe emulator, it can use the services of the Android platform to invoke otherapplications, 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 consolefrom which you can log kernel output, simulate application interrupts (such asarriving SMS messages or phone calls), and simulate latency effects and dropoutson the data network.
Overview
The Android emulator is an application that provides a virtualmobile device on which you can run your Android applications. It runs a fullAndroid system stack, down to the kernel level, that includes a set ofpreinstalled applications (such as the dialer) that you can access from yourapplications. You can choose what version of the Android system you want torun in the emulator by configuring AVDs, and you can also customize themobile 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 containcode for the Android Linux kernel, the native libraries, the Dalvik VM, and thevarious Android packages (such as the Android framework and preinstalledapplications). The emulator provides dynamic binary translation of devicemachine code to the OS and processor architecture of your developmentmachine.
The Android emulator supports many hardware features likely to be found onmobile 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/Phonebuttons)
- A sound chip with output and input capabilities
- Flash memory partitions (emulated through disk image files on thedevelopment 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 Androidapplications in more detail.
Android Virtual Devices and the Emulator
To use the emulator, you first must create one or more AVD configurations. In eachconfiguration, you specify an Android platform to run in the emulator and the set of hardwareoptions and emulator skin you want to use. Then, when you launch the emulator, you specifythe AVD configuration that you want to load.
Each AVD functions as an independent device, with its own private storage foruser data, SD card, and so on. When you launch the emulator with an AVD configuration,it automatically loads the user data and SD card data from the AVD directory. By default,the emulator stores the user data, SD card data, and cache in the AVD directory.
To create and manage AVDs you use the AVD Manager UI or the android
toolthat is included in the SDK.For complete information about how to set up AVDs, see Managing Virtual Devices.
Starting and Stopping the Emulator
During development and testing of your application, you install and run yourapplication in the Android emulator. You can launch the emulator as a standaloneapplication from a command line, or you can run it from within your Eclipsedevelopment environment. In either case, you specify the AVD configuration toload and any startup options you want to use, as described in this document.
You can run your application on a single instance of the emulator or,depending on your needs, you can start multiple emulator instances and run yourapplication in more than one emulated device. You can use the emulator'sbuilt-in commands to simulate GSM phone calling or SMS between emulatorinstances, and you can set up network redirection that allows emulators to senddata to one another. For more information, see TelephonyEmulation, SMS Emulation, andEmulator Networking
To start an instance of the emulator from the command line, navigate to thetools/
folder of the SDK. Enter emulator
commandlike this:
This initializes the emulator, loads an AVD configuration and displays the emulatorwindow. For more information about command line options for the emulator, see theAndroid Emulator tool reference.
Note: You can run multipleinstances of the emulator concurrently, each with its own AVD configuration andstorage area for user data, SD card, and so on.
If you are working in Eclipse, the ADT plugin for Eclipse installs yourapplication and starts the emulator automatically, when you run or debugthe application. You can specify emulator startup options in the Run/Debugdialog, in the Target tab. When the emulator is running, you can issueconsole commands as described later in this document.
If you are not working in Eclipse, see Installing Applicationson 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, seethe Android Emulator toolreference.
Installing Applications on the Emulator
If you don't have access to Eclipse or the ADT Plugin, you can install your application on theemulator using the adb utility. Beforeinstalling the application, you need to build and package it into an .apk
as describedin Building andRunning Apps. Once the application is installed, you can start the emulator from the commandline as described previously, using any startup options necessary.When the emulator is running, you can also connect to the emulator instance'sconsole to issue commands as needed.
As you update your code, you periodically package and install it on the emulator.The emulator preserves the application and its state data across restarts,in a user-data disk partition. To ensure that the application runs properlyas 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.
Using Hardware Acceleration
Android For Mac
In order to make the Android emulator run faster and be more responsive, you can configure it totake advantage of hardware acceleration, using a combination of configuration options, specificAndroid system images and hardware drivers.
Configuring Graphics Acceleration
Caution: As of SDK Tools Revision 17, the graphicsacceleration feature for the emulator is experimental; be alert for incompatibilities anderrors when using this feature.
Graphics acceleration for the emulator takes advantage of your development computer's graphicshardware, specifically its graphics processing unit (GPU), to make screen drawing faster. To usethe graphics acceleration feature, you must have the following versions of the Android developmenttools installed:
- Android SDK Tools, Revision 17 or higher
- Android SDK Platform API 15, Revision 3 or higher
Use the Android SDKManager to install these components:
Note: Not all applications are compatible with graphics hardwareacceleration. In particular, the Browser application and applications using the WebView
component are not compatible with graphics acceleration.
To configure an AVD to use graphics acceleration:
- Make sure you have the required SDK components installed (listed above).
- Start the AVD Manager and create a new AVD with the Target value ofAndroid 4.0.3 (API Level 15), revision 3 or higher.
- If you want to have graphics acceleration enabled by default for this AVD, in theHardware section, click New, select GPU emulationand set the value to Yes.
Note: You can also enable graphics acceleration when youstart an emulator using command line options as describe in the next section.
- Name the AVD instance and select any other configuration options.
Caution: Do not select the Snapshot: Enabledoption. Snapshots are not supported for emulators with graphics acceleration enabled.
- Click Create AVD to save the emulator configuration.
If you set GPU emulation to Yes for your AVD, then graphicsacceleration is automatically enabled when you run it. If you did not enable GPUemulation when you created the AVD, you can still enable it at runtime.
To enable graphics acceleration at runtime for an AVD:
- If you are running the emulator from the command line, just include the
-gpu on
option:Note: You must specify an AVD configuration that usesAndroid 4.0.3 (API Level 15, revision 3) or higher system image target. Graphics acceleration is notavailable for earlier system images.
- If you are running the emulator from Eclipse, run your Android application using an AVD withthe
-gpu on
option enabled:- In Eclipse, click your Android project folder and then select Run > RunConfigurations..
- In the left panel of the Run Configurations dialog, select your Androidproject run configuration or create a new configuration.
- Click the Target tab.
- Select the AVD you created in the previous procedure.
- In the Additional Emulator Command Line Options field, enter:
-gpu on
- Run your Android project using this run configuration.
Configuring Virtual Machine Acceleration
Samsung z2 source file download. Caution: As of SDK Tools Revision 17, the virtual machineacceleration feature for the emulator is experimental; be alert for incompatibilities and errorswhen using this feature.
Many modern CPUs provide extensions for running virtual machines (VMs) more efficiently. Takingadvantage of these extensions with the Android emulator requires some additional configuration ofyour development system, but can significantly improve the execution speed. Before attempting to usethis type of acceleration, you should first determine if your development system’s CPU supports oneof the following virtualization extensions technologies:
- Intel Virtualization Technology (VT, VT-x, vmx) extensions
- AMD Virtualization (AMD-V, SVM) extensions (only supported for Linux)
The specifications from the manufacturer of your CPU should indicate if it supportsvirtualization extensions. If your CPU does not support one of these virtualization technologies,then you cannot use virtual machine acceleration.
Note: Virtualization extensions are typically enabled throughyour computer's BIOS and are frequently turned off by default. Check the documentation for yoursystem's motherboard to find out how to enable virtualization extensions.
Once you have determined that your CPU supports virtualization extensions, make sure you can workwithin these additional requirements of running an emulator inside an accelerated virtualmachine:
- x86 AVD Only - You must use an AVD that is uses an x86 system image target.AVDs that use ARM-based system images cannot be accelerated using the emulator configurationsdescribed here.
- Not Inside a VM - You cannot run a VM-accelerated emulator inside anothervirtual machine, such as a VirtualBox or VMWare-hosted virtual machine. You must run the emulatordirectly on your system hardware.
- Other VM Drivers - If you are running another virtualization technology onyour system such as VirtualBox or VMWare, you may need to unload the driver for that virtual machinehosting software before running an accelerated emulator.
- OpenGL® Graphics - Emulation of OpenGL ES graphics may not perform at thesame level as an actual device.
To use virtual machine acceleration with the emulator, you need the following version of Androiddevelopment tools. Use the Android SDKManager to install these components:
- Android SDK Tools, Revision 17 or higher
- Android x86-based system image
If your development environment meets all of the requirements for running a VM-acceleratedemulator, you can use the AVD Manager to create an x86-based AVD configuration:
- In the Android SDK Manager, make sure you have an x86-based System Image installed for your target Android version. If you do not have an x86 System Image installed, select one in the Android SDK Manager and install it.
Tip: System images are listed under each API Level in the SDK Manager. An x86 system image may not be available for all API levels.
- Start the AVD Manager and create a new AVD with an x86 value for theCPU/ABI field. You may need to select a specific Target value, orselect a Target value and then select a specific CPU/ABIoption.
- Name the emulator instance and select any other configuration options.
- Click Create AVD to save the emulator configuration.
Configuring VM Acceleration on Windows
Virtual machine acceleration for Windows requires the installation of the Intel HardwareAccelerated Execution Manager (Intel HAXM). The software requires an Intel CPU withVirtualization 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:
- Start the Android SDK Manager, select Extras and then select IntelHardware Accelerated Execution Manager.
- After the download completes, execute
<sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/IntelHAXM.exe
. - Follow the on-screen instructions to complete installation.
- After installation completes, confirm that the virtualization driver is operating correctly byopening a command prompt window and running the following command:
You should see a status message including the following information:
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:
Note: You must provide an x86-based AVD configurationname, otherwise VM acceleration will not be enabled.
- If you are running the emulator from Eclipse, run your Android application with an x86-basedAVD:
- In Eclipse, click your Android project folder and then select Run > RunConfigurations..
- In the left panel of the Run Configurations dialog, select your Androidproject run configuration or create a new configuration.
- Click the Target tab.
- Select the x86-based AVD you created previously.
- Run your Android project using this run configuration.
You can adjust the amount of memory available to the Intel HAXM kernel extension by re-runningits installer.
You can stop using the virtualization driver by uninstalling it. Re-run the installer or usethe Control Panel to remove the software.
Configuring VM Acceleration on Mac
Virtual machine acceleration on a Mac requires the installation of the Intel Hardware AcceleratedExecution Manager (Intel HAXM) kernel extension to allow the Android emulator to make use of CPUvirtualization extensions. The kernel extension is compatible with Mac OS X Snow Leopard (version10.6.0) and higher.
To install the Intel HAXM kernel extension:
- Start the Android SDK Manager, select Extras and then select IntelHardware Accelerated Execution Manager.
- After the download completes, execute
<sdk>/extras/intel/Hardware_Accelerated_Execution_Manager/IntelHAXM.dmg
. - Double click the IntelHAXM.mpkg icon to begin installation.
- Follow the on-screen instructions to complete installation.
- After installation completes, confirm that the new kernel extension is operating correctly byopening a terminal window and running the following command:
You should see a status message containing the following extension name, indicating that the kernel extension is loaded:
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:
Note: You must provide an x86-based AVD configurationname, otherwise VM acceleration will not be enabled.
- If you are running the emulator from Eclipse, run your Android application with an x86-basedAVD:
- In Eclipse, click your Android project folder and then select Run > RunConfigurations..
- In the left panel of the Run Configurations dialog, select your Androidproject run configuration or create a new configuration.
- Click the Target tab.
- Select the x86-based AVD you created previously.
- Run your Android project using this run configuration.
You can adjust the amount of memory available to the Intel HAXM kernel extension by re-runningthe installer.
You can stop using the virtualization kernel driver by uninstalling it. Before removing it, shutdown any running x86 emulators. To unload the virtualization kernel driver, run the followingcommand in a terminal window:
Configuring VM Acceleration on Linux
Linux-based systems support virtual machine acceleration through the KVM software package. Followinstructions for installing KVM on yourLinux system, and verify that KVM is enabled. In addition to following the installationinstructions, be aware of these configuration requirements:
- Running KVM requires specific user permissions, make sure you have sufficient permissionsaccording to the KVM installation instructions.
- If you use another virtualization technology in your Linux platform, unload its kernel driverbefore 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-basedAVD and include the KVM options:
Note: You must provide an x86-based AVD configurationname, otherwise VM acceleration will not be enabled.
- If you are running the emulator from Eclipse, run your Android application with an x86-basedAVD and include the KVM options:
- In Eclipse, click your Android project folder and then select Run > RunConfigurations..
- In the left panel of the Run Configurations dialog, select your Androidproject run configuration or create a new configuration.
- Click the Target tab.
- Select the x86-based AVD you created previously.
- In the Additional Emulator Command Line Options field, enter:
- Run your Android project using this run configuration.
Important: When using the -qemu
command line option, make sureit is the last parameter in your command. All subsequent options are interpreted as qemu-specificparameters.
SD Card Emulation
You can create a disk image and then load it to the emulator at startup, tosimulate the presence of a user's SD card in the device. To do this, you can specifyan SD card image when you create an AVD, or you can use the mksdcard utility includedin the SDK.
The following sections describe how to create an SD card disk image, how to copyfiles 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, youcan not remove a simulated SD card from a running emulator. However, you canbrowse, send files to, and copy/remove files from a simulated SD card eitherwith adb or the emulator.
The emulator supports emulated SDHC cards, so you can create an SD card imageof any size up to 128 gigabytes.
Creating an SD card image
There are several ways of creating an SD card image. The easiest way is to use theAVD 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:
The -c
option can also be used to to specify a path to an SD cardimage for the new AVD. For more information, see Managing Virtual Devicesfrom the Command Line.
You can also use the mksdcard tool, included in the SDK, to create a FAT32 diskimage that you can load in the emulator at startup. You can access mksdcard inthe tools/ directory of the SDK and create a disk image like this:
For example: Alarm app.
For more information, see mksdcard
.
Copying files to an SD card image
Once you have created the disk image, you can copy files to it prior toloading it in the emulator. To copy files, you can mount the image as a loopdevice and then copy the files to it, or you can use a utility such as mtools
tocopy the files directly to the image. The mtools
package is available for Linux,Mac, and Windows.
Alternatively, you can use the adb push
command to move files onto an SD card imagewhile it is loaded in an emulator. For more information see the adb push
documentation.
Loading an SD card image
By default, the emulator loads the SD card image that is stored with the activeAVD (see the -avd
startup option).
Alternatively, you can start the emulator with the-sdcard
flag and specify the name and path of your image (relativeto the current working directory):
Working with Emulator Disk Images
The emulator uses mountable disk images stored on your development machine tosimulate flash (or similar) partitions on an actual device. For example, it uses adisk image containing an emulator-specific kernel, the Android system, aramdisk image, and writeable images for user data and simulated SD card.
To run properly, the emulator requires access to a specific set of disk imagefiles. By default, the Emulator always looks for the disk images in theprivate storage area of the AVD in use. If no images exist there whenthe Emulator is launched, it creates the images in the AVD directory based ondefault versions stored in the SDK.
Note: The default storage location forAVDs is in ~/.android/avd
on OS X and Linux, C:Documents andSettings<user>.android
on Windows XP, andC:Users<user>.android
on Windows Vista.
To let you use alternate or custom versions of the image files, the emulatorprovides startup options that override the default locations and filenames ofthe image files. When you use one of these options, the emulator searches for the imagefile under the image name or location that you specify; if it can not locate theimage, it reverts to using the default names and location.
The emulator uses three types of image files: default image files, runtimeimage files, and temporary image files. The sections below describe how tooverride the location/name of each type of file.
Default image files
When the emulator launches, but does not find an existing user data image inthe active AVD's storage area, it creates a new one from a default versionincluded in the SDK. The default user data image is read-only. The imagefiles are read-only.
The emulator provides the -system <dir>
startup option tolet you override the location where the emulator looks for the defaultuser data image.
The emulator also provides a startup option that lets you override the nameof the default user data image, as described in the following table. When you use theoption, the emulator looks in the default directory, or in a custom location(if you specified -system <dir>
).
Name | Description | Comments |
---|---|---|
userdata.img | The initial user-data disk image | Override using -initdata <file> . Also see-data <file> , below. |
Runtime images: user data and SD card
At runtime, the emulator reads and writes data to two disk images: auser-data image and (optionally) an SD card image. These images emulate the user-datapartition and removable storage media on actual device.
The emulator provides a default user-data disk image. At startup, the emulatorcreates the default image as a copy of the system user-data image (user-data.img),described above. The emulator stores the new image with the files of the active AVD.
The emulator provides startup options to let you override the actual names and storagelocations of the runtime images to load, as described in the following table. When you use oneof these options, the emulator looks for the specified file(s) in the current working directory,in the AVD directory, or in a custom location (if you specified a path with the filename).
Name | Description | Comments |
---|---|---|
userdata-qemu.img | An image to which the emulator writes runtime user-data for a unique user. | Override using -data <filepath> , where <filepath> is thepath the image, relative to the current working directory. If you supply a filename only,the emulator looks for the file in the current working directory. If the file at <filepath> doesnot exist, the emulator creates an image from the default userdata.img, stores it under the name youspecified, and persists user data to it at shutdown. |
sdcard.img | An image representing an SD card inserted into the emulated device. | Override using -sdcard <filepath> , where <filepath> is thepath the image, relative to the current working directory. If you supply a filename only,the emulator looks for the file in the current working directory. |
User-Data Image
Each emulator instance uses a writeable user-data image to store user- andsession-specific data. For example, it uses the image to store a unique user'sinstalled application data, settings, databases, and files.
At startup, the emulator attempts to load a user-data image stored duringa 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/namethat you specified at startup.
- If it finds a user-data image, it mounts the image and makes it availableto the system for reading and writing of user data.
- If it does not find one, it creates an image by copying the system user-dataimage (userdata.img), described above. At device power-off, the system persiststhe 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 youspecify 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 needto 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 useto simulate removeable storage in an actual device. For information about how to create anemulated 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 imagefor you, when creating an AVD. For more information, see Managing Virtual Devices with AVDManager.
Temporary Images
The emulator creates two writeable images at startup that it deletes atdevice 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 orpersisting it at device power-off.
The /cache
partition image is initially empty, and is used bythe browser to cache downloaded web pages and images. The emulator provides an-cache <file>
, which specifies the name of the file in whichto 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 toset up complex modeling and testing environments for your application. Thesections below introduce the emulator's network architecture and capabilities.
Network Address Space
Each instance of the emulator runs behind a virtual router/firewall servicethat isolates it from your development machine's network interfaces and settingsand from the internet. An emulated device can not see your development machineor other emulator instances on the network. Instead, it sees only that it isconnected through Ethernet to a router/firewall.
The virtual router for each instance manages the 10.0.2/24 network addressspace — all addresses managed by the router are in the form of10.0.2.<xx>, where <xx> is a number. Addresses within this space arepre-allocated by the emulator/router as follows:
Network Address | Description |
---|---|
10.0.2.1 | Router/gateway address |
10.0.2.2 | Special alias to your host loopback interface (i.e., 127.0.0.1 on yourdevelopment machine) |
10.0.2.3 | First DNS server |
10.0.2.4 / 10.0.2.5 / 10.0.2.6 | Optional second, third and fourth DNS server (if any) |
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 emulatorinstances. That means that if you have two instances running concurrently onyour machine, each will have its own router and, behind that, each will have anIP address of 10.0.2.15. The instances are isolated by a router and cannot see each other on the same network. For information about how tolet emulator instances communicate over TCP/UDP, see Connecting Emulator Instances.
Also note that the address 127.0.0.1 on your development machine correspondsto the emulator's own loopback interface. If you want to access services runningon your development machine's loopback interface (a.k.a. 127.0.0.1 on yourmachine), you should use the special address 10.0.2.2 instead.
Finally, note that each emulated device's pre-allocated addresses arespecific to the Android emulator and will probably be very different on realdevices (which are also very likely to be NAT-ed, i.e., behind arouter/firewall)
Local Networking Limitations
Android applications running in an emulator can connect to the network available on yourworkstation. However, they connect through the emulator, not directly to hardware, and the emulatoracts like a normal application on your workstation. This means that the emulator, and thus yourAndroid applications, are subject to some limitations:
- Communication with the emulated device may be blocked by a firewallprogram running on your machine.
- Communication with the emulated device may be blocked by another(physical) firewall/router to which your machine is connected.
The emulator's virtual router should be able to handle all outbound TCP andUDP connections/messages on behalf of the emulated device, provided yourdevelopment machine's network environment allows it to do so. There are nobuilt-in limitations on port numbers or ranges except the one imposed by yourhost operating system and network.
Depending on the environment, the emulator may not be able to support otherprotocols (such as ICMP, used for 'ping') might not be supported. Currently, theemulator does not support IGMP or multicast.
Using Network Redirection
To communicate with an emulator instance behind its virtual router, you needto set up network redirection on the virtual router. Clients can then connectto a specified guest port on the router, while the router directs trafficto/from that port to the emulated device's host port.
To set up the network redirection, you create a mapping of host and guestports/addresses on the the emulator instance. There are two ways to set upnetwork redirection: using emulator console commands and using the ADB tool, asdescribed below.
Setting up Redirection through the Emulator Console
Each emulator instance provides a control console the you can connect to, toissue commands that are specific to that instance. You can use theredir
console command to set up redirection as needed for anemulator instance.
First, determine the console port number for the target emulator instance.For example, the console port number for the first emulator instance launched is5554. Next, connect to the console of the target emulator instance, specifyingits console port number, as follows:
Once connected, use the redir
command to work with redirection.To add a redirection, use:
where <protocol>
is either tcp
or udp
,and <host-port>
and <guest-port>
sets themapping between your own machine and the emulated system, respectively.
For example, the following command sets up a redirection that handles allincoming TCP connections to your host (development) machine on 127.0.0.1:5000and will pass them through to the emulated system's 10.0.2.15:6000.:
To delete a redirection, you can use the redir del
command. Tolist all redirection for a specific instance, you can use redirlist
. For more information about these and other console commands, seeUsing the Emulator Console.
Note that port numbers are restricted by your local environment. this typicallymeans that you cannot use host port numbers under 1024 without specialadministrator privileges. Also, you won't be able to set up a redirection for ahost port that is already in use by another process on your machine. In thatcase, redir
generates an error message to that effect.
Setting Up Redirection through ADB
The Android Debug Bridge (ADB) tool provides port forwarding, an alternateway for you to set up network redirection. For more information, see Forwarding Ports in the ADBdocumentation.
Note that ADB does not currently offer any way to remove a redirection,except by killing the ADB server.
Configuring the Emulator's DNS Settings
At startup, the emulator reads the list of DNS servers that your system iscurrently using. It then stores the IP addresses of up to four servers on thislist and sets up aliases to them on the emulated addresses 10.0.2.3, 10.0.2.4,10.0.2.5 and 10.0.2.6 as needed.
On Linux and OS X, the emulator obtains the DNS server addresses by parsingthe file /etc/resolv.conf
. On Windows, the emulator obtains theaddresses by calling the GetNetworkParams()
API. Note that thisusually means that the emulator ignores the content of your 'hosts' file(/etc/hosts
on Linux/OS X, %WINDOWS%/system32/HOSTS
on Windows).
When starting the emulator at the command line, you can also use the-dns-server <serverList>
option to manually specify theaddresses of DNS servers to use, where <serverList> is a comma-separatedlist of server names or IP addresses. You might find this option useful if youencounter DNS resolution problems in the emulated network (for example, an'Unknown Host error' message that appears when using the web browser).
Using the Emulator with a Proxy
If your emulator must access the Internet through a proxy server, you can usethe -http-proxy <proxy>
option when starting the emulator, toset up the appropriate redirection. In this case, you specify proxy informationin <proxy>
in one of these formats:
or
The -http-proxy
option forces the emulator to use the specifiedHTTP/HTTPS proxy for all outgoing TCP connections. Redirection for UDP is notcurrently supported.
Alternatively, you can define the environment variablehttp_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 — theemulator checks the value of the http_proxy
environment variable atstartup and uses its value automatically, if defined.
You can use the -verbose-proxy
option to diagnose proxyconnection problems.
Interconnecting Emulator Instances
To allow one emulator instance to communicate with another, you must set upthe necessary network redirection as illustrated below.
Assume that your environment is
- A is you development machine
- B is your first emulator instance, running on A
- C is your second emulator instance, also running on A
and you want to run a server on B, to which C will connect, here is how youcould set it up:
- Set up the server on B, listening to
10.0.2.15:<serverPort>
- On B's console, set up a redirection from
A:localhost:<localPort>
toB:10.0.2.15:<serverPort>
- On C, have the client connect to
10.0.2.2:<localPort>
For example, if you wanted to run an HTTP server, you can select<serverPort>
as 80 and <localPort>
as8080:
- B listens on 10.0.2.15:80
- On B's console, issue
redir add tcp:8080:80
- C connects to 10.0.2.2:8080
Sending a Voice Call or SMS to Another Emulator Instance
The emulator automatically forwards simulated voice calls and SMS messages from one instance toanother. To send a voice call or SMS, use the dialer application or SMS application, respectively,from one of the emulators.
To initiate a simulated voice call to another emulator instance:
- Launch the dialer application on the originating emulator instance.
- As the number to dial, enter the console port number of the instance you'd like to call. You can determine the console port number of the target instance by checking its window title, where the console port number is reported as 'Android Emulator (<port>).
- Press 'Dial'. A new inbound call appears in the target emulator instance.
To send an SMS message to another emulator instance, launch the SMS application (if available). Specify the console port number of the target emulator instance as as the SMS address, enter the message text, and send the message. The message is delivered to the target emulator instance.
You can also connect to an emulator instance's console to simulate an incoming voice call or SMS. For more information, see Telephony Emulation and SMS Emulation.
Using the Emulator Console
Each running emulator instance provides a console that lets you query and control the emulateddevice environment. For example, you can use the console to manage port redirection, networkcharacteristics, and telephony events while your application is running on the emulator. Toaccess the console and enter commands, use telnet to connect to the console's port number.
To connect to the console of any running emulator instance at any time, use this command:
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 consoleof 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.
Android Emulator Online
To exit the console session, use quit
or exit
.
Mac Os X Android Emulator
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. Afteryou connect to the console, manage port redirection by entering the following command:
Os X Android Emulator Download
The redir
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
list | List the current port redirection. | |
add <protocol>:<host-port>:<guest-port> | Add a new port redirection. |
|
del <protocol>:<host-port> | Delete a port redirection. | The meanings of <protocol> and <host-port> are listed in the previous row. |
Geo Location Provider Emulation
You can use the console to set the geographic location reported to the applications runninginside an emulator. Use the geo
command to send a simple GPS fix to theemulator, with or without NMEA 1083 formatting:
The geo
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
fix <longitude> <latitude> [<altitude>] | Send a simple GPS fix to the emulator instance. | Specify longitude and latitude in decimal degrees. Specify altitude in meters. |
nmea <sentence> | Send an NMEA 0183 sentence to the emulated device, as if it were sent from an emulated GPS modem. | <sentence> must begin with '$GP'. Only '$GPGGA' and '$GPRCM' sentences are currently supported. |
You can issue the geo
command as soon as an emulator instance is running. Theemulator sets the location you enter by creating a mock location provider. This provider responds tolocation listeners set by applications, and also supplies the location to the LocationManager
. Any application can query the location manager to obtain thecurrent GPS fix for the emulated device by calling:
For more information about the Location Manager, see LocationManager
.
Hardware Events Emulation
The event
console commands sends hardware events to the emulator. The syntax for thiscommand is as follows:
The event
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
send <type>:<code>:<value> [..] | Send one or more events to the Android kernel. | You can use text names or integers for <type> and <value> . |
types | List all <type> string aliases supported by the event subcommands. | |
codes <type> | List all <codes> string aliases supported by the event subcommands for the specified <type> . | |
event text <message> | Simulate keypresses to send the specified string of characters as a message, | The message must be a UTF-8 string. Unicode posts will be reverse-mapped according to the current device keyboard. Unsupported characters will be discarded silently. |
Device Power Characteristics
The power
command controls the power state reported by the emulator to applications. Thesyntax for this command is as follows:
The event
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
display | Display battery and charger state. | |
ac <on|off> | Set AC charging state to on or off. | |
status <unknown|charging|discharging|not-charging|full> | Change battery status as specified. | |
present <true|false> | Set battery presence state. | |
health <unknown|good|overheat|dead|overvoltage|failure> | Set battery health state. | |
power health <percent> | 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 Delay Emulation
The emulator lets you simulate various network latency levels, so that you can test yourapplication in an environment more typical of the actual conditions in which it will run. You canset a latency level or range at emulator startup or you can use the console to change the latency,while the application is running in the emulator.
To set latency at emulator startup, use the -netdelay
emulator option with asupported <delay>
value, as listed in the table below. Here are someexamples:
To make changes to network delay while the emulator is running, connect to the console and usethe netdelay
command with a supported <delay>
value from the tablebelow.
The format of network <delay> is one of the following (numbers are milliseconds):
Value | Description | Comments |
---|---|---|
gprs | GPRS | (min 150, max 550) |
edge | EDGE/EGPRS | (min 80, max 400) |
umts | UMTS/3G | (min 35, max 200) |
none | No latency | (min 0, max 0) |
<num> | Emulate an exact latency (milliseconds). | |
<min>:<max> | Emulate an specified latency range (min, max milliseconds). |
Network Speed Emulation
The emulator also lets you simulate various network transfer rates.You can set a transfer rate or range at emulator startup or you can use the console to change therate, while the application is running in 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:
To make changes to network speed while the emulator is running, connect to the console and usethe netspeed
command with a supported <speed>
value from the tablebelow.
The format of network <speed>
is one of the following (numbers arekilobits/sec):
Value | Description | Comments |
---|---|---|
gsm | GSM/CSD | (Up: 14.4, down: 14.4) |
hscsd | HSCSD | (Up: 14.4, down: 43.2) |
gprs | GPRS | (Up: 40.0, down: 80.0) |
edge | EDGE/EGPRS | (Up: 118.4, down: 236.8) |
umts | UMTS/3G | (Up: 128.0, down: 1920.0) |
hsdpa | HSDPA | (Up: 348.0, down: 14400.0) |
full | no limit | (Up: 0.0, down: 0.0) |
<num> | Set an exact rate used for both upload and download. | |
<up>:<down> | Set exact rates for upload and download separately. |
Telephony Emulation
The Android emulator includes its own GSM emulated modem that lets you simulate telephonyfunctions in the emulator. For example, you can simulate inbound phone calls, establish dataconnections and terminate them. The Android system handles simulated calls exactly as it wouldactual calls. The emulator does not support call audio.
You can use the gsm
command to access the emulator's telephony functions after connectingto the console. The syntax for this command is as follows:
The gsm
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
call <phonenumber> | Simulate an inbound phone call from <phonenumber>. | |
accept <phonenumber> | Accept an inbound call from <phonenumber> and change the call's state 'active'. | You can change a call's state to 'active' only if its current state is 'waiting' or 'held'. |
busy <phonenumber> | Close an outbound call to <phonenumber> and change the call's state to 'busy'. | You can change a call's state to 'busy' only if its current state is 'waiting'. |
cancel <phonenumber> | Terminate an inbound or outbound phone call to/from <phonenumber>. | |
data <state> | Change the state of the GPRS data connection to <state>. | Supported <state> values are:
|
hold | Change the state of a call to 'held'. | You can change a call's state to 'held' only if its current state is 'active' or 'waiting'. |
list | List all inbound and outbound calls and their states. | |
voice <state> | Change the state of the GPRS voice connection to <state>. | Supported <state> values are:
|
status | Report the current GSM voice/data state. | Values are those described for the voice and data commands. |
SMS Emulation
The Android emulator console lets you generate an SMS message and direct it to an emulatorinstance. Once you connect to an emulator instance, you can generate an emulated incoming SMS usingthe following command:
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 forthis command is as follows:
The vm
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
start | Start the VM on the instance. | |
stop | Stop the VM on the instance. | |
start | 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 thiscommand is as follows:
The vm
command supports the subcommands listed in the table below.
Subcommand | Description | Comments |
---|---|---|
scale <scale> | Scale the emulator window. | 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. |
Terminating an Emulator Instance
You can terminate an emulator instance through the console, using the kill
command.
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
Troubleshooting Emulator Problems
The adb
utility sees the emulator as an actual physical device. For this reason, youmight have to use the -d
flag with some common adb
commands, such asinstall
. The -d
flag lets you specify which of several connected devices to useas the target of a command. If you don't specify -d
, the emulator targets the firstdevice in its list. For more information about adb
, see Android Debug Bridge.
For emulators running on Mac OS X, if you see an error Warning: No DNS servers found
when starting the emulator, check to see whether you have an /etc/resolv.conf
file. Ifnot, please run the following line in a command window:
See Frequently Asked Questions for moretroubleshooting information.