Show
Page 2
The Android SDK includes an Android device emulator — a virtual device that runs on your computer. The Android Emulator lets you develop and test Android apps without using a physical device. This page describes command-line features that you can use with the Android Emulator. For information about using the Android Emulator UI, see Run Apps on the Android Emulator. Starting the emulatorUse the emulator command to start the emulator, as an alternative to running your project or starting it through the AVD Manager. Here's the basic command-line syntax for starting a virtual device from a terminal prompt: emulator -avd avd_name [ {-option [value]} … ]Or emulator @avd_name [ {-option [value]} … ]For example, if you launch the emulator from within Android Studio running on a Mac, the default command line will be similar to the following: /Users/janedoe/Library/Android/sdk/emulator/emulator -avd Nexus_5X_API_23 -netdelay none -netspeed fullYou can specify startup options when you start the emulator, but not later on. For a list of AVD names, enter the following command: emulator -list-avdsWhen you use this option, it displays a list of AVD names from your Android home directory. Note that you can override the default home directory by setting the ANDROID_SDK_HOME environment variable: the root of the user-specific directory where all configuration and AVD content is stored. You could set the environment variable in the terminal window before launching a virtual device, or you could set it through your user settings in the operating system; for example, in your .bashrc file on Linux. To stop the Android Emulator, just close the emulator window. Installing an appIn addition to installing an app through Android Studio or the emulator UI, you can install your app on a virtual device by using the adb utility. To install an app by using adb, and then run and test the app, follow these general steps:
Note: The adb utility sees the virtual device as an actual physical device. For this reason, you might have to use the -d flag with some common adb commands, such as install. The -d flag lets you specify which of several connected devices to use as the target of a command. If you don't specify -d, the emulator targets the first device in its list. Understanding the default directories and filesThe emulator uses associated files, of which the AVD system and data directories are the most important. It helps to understand the emulator directory structure and files when specifying command-line options. Although, you normally don't need to modify the default directories or files. The Android Emulator uses the Quick Emulator (QEMU) hypervisor. Initial versions of the Android Emulator used QEMU 1 (goldfish), and later versions use QEMU 2 (ranchu). AVD system directoryThe system directory contains the Android system images that the emulator uses to simulate the operating system. It has platform-specific, read-only files shared by all AVDs of the same type, including API level, CPU architecture, and Android variant. The default locations are the following:
Where:
Use the -sysdir option to specify a different system directory for the AVD. The emulator reads the following files from the system directory.
AVD data directoryThe AVD data directory, also called the content directory, is specific to a single AVD instance and contains all modifiable data for the AVD. The default location is the following, where name is the AVD name:
Use the -datadir option to specify a different AVD data directory. The following table lists the most important files contained in this directory.
Listing directories and files used by the emulatorYou can discover where files are located in two ways:
Command-line startup optionsThis section lists options you can supply on the command line when you start the emulator. Note: The Android Emulator is continually under development to make it more reliable. For status on the issues reported against various command-line options, and to report bugs, see the Android Issue Tracker. Commonly used optionsThe following table lists command-line startup options that you might use more often.
Advanced optionsThe following command-line startup options are available, but not commonly used by the average app developer. In the descriptions, the working directory is the current directory in the terminal where you're entering commands. For information about the AVD system directory and data directory, and the files stored within them, see Understanding the default directories and files. Some of these options are appropriate for external app developers, and some of them are used primarily by platform developers. App developers create Android apps and run them on specific AVDs. Platform developers work on the Android system and run it inside the emulator with no pre-created AVD; they're internal Android team members, not external app developers.
Deprecated optionsThe following command-line options are deprecated:
Getting help about command-line optionsThis section describes how to get help about the command-line options. The following section provides more in-depth information about the commonly used emulator command-line options that are available when you start the emulator. Listing all emulator optionsTo print a list of all emulator options, including a short description, enter this command: emulator -helpGetting detailed help for a specific optionTo print help for a specific startup option, enter this command: emulator -help-optionFor example: emulator -help-netspeedThis help is more detailed than the description provided by the -help option. Getting detailed help for all optionsTo get detailed help for all emulator options, enter this command: emulator -help-allListing emulator environment variablesTo get a list of emulator environment variables, enter this command: emulator -help-environmentYou can set environment variables in the terminal window before launching a virtual device, or you could set it through your user settings in the operating system; for example, in your .bashrc file on Linux. Listing debug tagsTo print a list of tags for the -debug options, enter this command: emulator -help-debug-tagsThe -debug options let you enable or disable debug messages from specific emulator components, as specified by the tags. |