Android Studio Overview

634
Android Studio Overview In this document 1. Project and File Structure 2. Android Build System 3. Debug and Performance 4. Installation, Setup, and Update Management 5. Other Highlights See also 1. IntelliJ FAQ on migrating to IntelliJ IDEA Android Studio is the official IDE for Android application development, based on IntelliJ IDEA . On top of the capabilities you expect from IntelliJ, Android Studio offers: Flexible Gradle-based build system Build variants and multiple apk file generation Code templates to help you build common app features Rich layout editor with support for drag and drop theme editing Lint tools to catch performance, usability, version compatibility, and other problems ProGuard and app-signing capabilities Built-in support for Google Cloud Platform , making it easy to integrate Google Cloud Messaging and App Engine And much more Download Android Studio now . If you're new to Android Studio or the IntelliJ IDEA interface, this page provides an introduction to some key Android Studio features. For specific Android Studio how-to documentation, see the pages in the Workflow section, such as Managing Projects from Android Studio and Building and Running from Android Studio . Project and File Structure

description

Android

Transcript of Android Studio Overview

Android Studio OverviewIn this document1. Project and File Structure2. Android Build System3. Debug and Performance4. Installation, Setup, and Update Management5. Other HighlightsSee also1. IntelliJ FAQ on migrating to IntelliJ IDEAAndroid Studio is the official IDE for Android application development, based on IntelliJ IDEA. On top of the capabilities you expect from IntelliJ, Android Studio offers: Flexible Gradle-based build system Build variants and multiple apk file generation Code templates to help you build common app features Rich layout editor with support for drag and drop theme editing Lint tools to catch performance, usability, version compatibility, and other problems ProGuard and app-signing capabilities Built-in support for Google Cloud Platform, making it easy to integrate Google Cloud Messaging and App Engine And much moreDownload Android Studio now. If you're new to Android Studio or the IntelliJ IDEA interface, this page provides an introduction to some key Android Studio features.For specific Android Studio how-to documentation, see the pages in the Workflow section, such as Managing Projects from Android Studio and Building and Running from Android Studio.Project and File Structure

Android Project ViewBy default, Android Studio displays your profile files in the Android project view. This view shows a flattened version of your project's structure that provides quick access to the key source files of Android projects and helps you work with the new Gradle-based build system. The Android project view: Groups the build files for all modules at the top level of the project hierarchy. Shows the most important source directories at the top level of the module hierarchy. Groups all the manifest files for each module. Shows resource files from all Gradle source sets. Groups resource files for different locales, orientations, and screen types in a single group per resource type.

Figure 1. Show the Android project view.

Figure 2. Project Build Files.The Android project view shows all the build files at the top level of the project hierarchy under Gradle Scripts. Each project module appears as a folder at the top level of the project hierarchy and contains these three elements at the top level: java/ - Source files for the module. manifests/ - Manifest files for the module. res/ - Resource files for the module.For example, Android project view groups all the instances of the ic_launcher.png resource for different screen densities under the same element.Note: The project structure on disk differs from this flattened representation. To switch to back the segregated project view, select Project from the Project New Project and Directory StructureWhen you use the Project view of a new project in Android Studio, you should notice that the project structure appears different than you may be used to in Eclipse. Each instance of Android Studio contains a project with one or more application modules. Each application module folder contains the complete source sets for that module, including src/main and src/androidTest directories, resources, build file and the Android manifest. For the most part, you will need to modify the files under each module's src/main directory for source code updates, the gradle.build file for build specification and the files under src/androidTest directory for test case creation.

Figure 3. Android Studio project structureFor more information, see IntelliJ project organization and Managing Projects.Creating new filesYou can quickly add new code and resource files by clicking the appropriate directory in the Project pane and pressing ALT + INSERT on Windows and Linux or COMMAND + N on Mac. Based on the type of directory selected, Android Studio offers to create the appropriate file type.For example, if you select a layout directory, press ALT + INSERT on Windows, and select Layout resource file, a dialog opens so you can name the file (you can exclude the .xml suffix) and choose a root view element. The editor then switches to the layout design editor so you can begin designing your layout.Android Build System

Android Build SystemThe Android build system is the toolkit you use to build, test, run and package your apps. This build system replaces the Ant system used with Eclipse ADT. It can run as an integrated tool from the Android Studio menu and independently from the command line. You can use the features of the build system to: Customize, configure, and extend the build process. Create multiple APKs for your app with different features using the same project and modules. Reuse code and resources across source sets.The flexibility of the Android build system enables you to achieve all of this without modifying your app's core source files. To build an Android Studio project, see Building and Running from Android Studio. To configure custom build settings in an Android Studio project, see Configuring Gradle Builds.Application ID for Package Identification With the Android build system, the applicationId attribute is used to uniquely identify application packages for publishing. The application ID is set in the android section of the build.gradle file. apply plugin: 'com.android.application'

android { compileSdkVersion 19 buildToolsVersion "19.1"

defaultConfig { applicationId "com.example.my.app" minSdkVersion 15 targetSdkVersion 19 versionCode 1 versionName "1.0" } ... Note: The applicationId is specified only in your build.gradle file, and not in the AndroidManifest.xml file.When using build variants, the build system enables you to to uniquely identify different packages for each product flavors and build types. The application ID in the build type is added as a suffix to those specified for the product flavors. productFlavors { pro { applicationId = "com.example.my.pkg.pro" } free { applicationId = "com.example.my.pkg.free" } }

buildTypes { debug { applicationIdSuffix ".debug" } } .... The package name must still be specified in the manifest file. It is used in your source code to refer to your R class and to resolve any relative activity/service registrations. package="com.example.app"> Note: If you have multiple manifests (for exmample, a product flavor specific manifest and a build type manifest), the package name is optional in those manifests. If it is specified in those manifests, the package name must be identical to the package name specified in the manifest in the src/main/ folder. For more information about the build files and process, see Build System Overview.Debug and Performance

Android Virtual Device (AVD) ManagerAVD Manager has updated screens with links to help you select the most popular device configurations, screen sizes and resolutions for your app previews.Click the Android Virtual Device Manager in the toolbar to open it and create new virtual devices for running your app in the emulator.The AVD Manager comes with emulators for Nexus 6 and Nexus 9 devices and also supports creating custom Android device skins based on specific emulator properties and assigning those skins to hardware profiles. Android Studio installs the Intel x86 Hardware Accelerated Execution Manager (HAXM) emulator accelerator and creates a default emulator for quick app prototyping.For more information, see Managing AVDs.Memory MonitorAndroid Studio provides a memory monitor view so you can more easily monitor your app's memory usage to find deallocated objects, locate memory leaks and track the amount of memory the connected device is using. With your app running on a device or emulator, click the Memory Monitor tab in the lower right corner to launch the memory monitor.

Figure 4. Memory MonitorNew Lint inspectionsLint has several new checks to ensure: Cipher.getInstance() is used with safe values In custom Views, the associated declare-styleable for the custom view uses the same base name as the class name. Security check for fragment injection. Where ever property assignment no longer works as expected. Gradle plugin version is compatible with the SDK. Right to left validation Required API version many othersHovering over a Lint error displays the full issue explanation inline for easy error resolution. There is also a helpful hyperlink at the end of the error message for additional error information.With Android Studio, you can run Lint for a specific build variant, or for all build variants. You can configure Lint by adding a lintOptions property to the Android settings in the build.gradle file. android { lintOptions { // set to true to turn off analysis progress reporting by lint quiet true // if true, stop the gradle build if errors are found abortOnError false // if true, only report errors ignoreWarnings true For more information, see Improving Your Code with Lint.Dynamic layout previewAndroid Studio allows you to work with layouts in both a Design View

Figure 5. Hello World App with Design Viewand a Text View. Figure 6. Hello World App with Text ViewEasily select and preview layout changes for different device images, display densities, UI modes, locales, and Android versions (multi-API version rendering).

Figure 7. API Version RenderingFrom the Design View, you can drag and drop elements from the Palette to the Preview or Component Tree. The Text View allows you to directly edit the XML settings, while previewing the device display. Log messagesWhen you build and run your app with Android Studio, you can view adb and device log messages (logcat) in the DDMS pane by clicking Android at the bottom of the window.If you want to debug your app with the Android Debug Monitor, you can launch it by clicking Monitor in the toolbar. The Debug Monitor is where you can find the complete set of DDMS tools for profiling your app, controlling device behaviors, and more. It also includes the Hierarchy Viewer tools to help optimize your layouts.Installation, Setup, and Update Management

Android Studio installation and setup wizardsAn updated installation and setup wizards walk you through a step-by-step installation and setup process as the wizard checks for system requirements, such as the Java Development Kit (JDK) and available RAM, and then prompts for optional installation options, such as the Intel HAXM emulator accelerator.An updated setup wizard walks you through the setup processes as the wizard updates your system image and emulation requirements, such GPU, and then creates an optimized default Android Virtual Device (AVD) based on Android 5 (Lollipop) for speedy and reliable emulation.

Figure 8. Setup WizardExpanded template and form factor supportAndroid Studio supports new templates for Google Services and expands the availabe device types. Android Wear and TV supportFor easy cross-platform development, the Project Wizard provides new templates for creating your apps for Android Wear and TV.

Figure 9. New Form FactorsDuring app creation, the Project Wizard also displays an API Level dialog to help you choose the best minSdkVersion for your project.Google App Engine integration (Google Cloud Platform/Messaging)Quick cloud integration. Using Google App Engine to connect to the Google cloud and create a cloud end-point is as easy as selecting File > New Module > App Engine Java Servlet Module and specifying the module, package, and client names.

Figure 10. Setup WizardUpdate channelsAndroid Studio provides four update channels to keep Android Studio up-to-date based on your code-level preference: Canary channel: Canary builds provide bleeding edge releases, updated about weekly. While these builds do get tested, they are still subject to bugs, as we want people to see what's new as soon as possible. This is not recommended for production. Dev channel: Dev builds are hand-picked older canary builds that survived the test of time. They are updated roughly bi-weekly or monthly. Beta channel: Beta builds are used for beta-quality releases before a production release. Stable channel: Used for stable, production-ready versions.By default, Android Studio uses the Stable channel. Use File > Settings > Updates to change your channel setting. Other Highlights

Translation EditorMulti-language support is enhanced with the Translation Editor plugin so you can easily add locales to the app's translation file. Color codes indicate whether a locale is complete or still missing string translations. Also, you can use the plugin to export your strings to the Google Play Developer Console for translation, then download and import your translations back into your project. To access the Translation Editor, open a strings.xml file and click the Open Editor link.

Figure 11. Translation EditorEditor support for the latest Android APIsAndroid Studio supports the new Material Design themes, widgets, and graphics, such as shadow layers and API version rendering (showing the layout across different UI versions). Also, the new drawable XML tags and attributes, such as and , are supported.Easy access to Android code samples on GitHubClicking Import Samples from the File menu or Welcome page provides seamless access to Google code samples on GitHub.

Figure 12. Code Sample AccessExcept as noted, this content is licensed under Creative Commons Attribution 2.5. For details and restrictions, see the Content License. About Android| Legal| Support

Android Studio Tips and TricksIn this document1. Productivity Features2. Working with IntelliJ3. Key CommandsSee also1. Download Android Studio2. IntelliJ IDEA Android Tutorials3. IntelliJ FAQ on migrating to IntelliJ IDEAIf you're unfamiliar with using Android Studio and the IntelliJ IDEA interface, this page provides some tips to help you get started with some of the most common tasks and productivity enhancements. Productivity Features

Android Studio includes a number of features to help you be more productive in your coding. This section notes a few of the key features to help you work quickly and efficiently. Smart RenderingWith smart rendering, Android Studio displays links for quick fixes to rendering errors. For example, if you add a button to the layout without specifying the width and height atttributes, Android Studio displays the rendering message Automatically add all missing attributs. Clicking the message adds the missing attributes to the layout.Bitmap rendering in the debuggerWhile debugging, you can now right-click on bitmap variables in your app and invoke View Bitmap. This fetches the associated data from the debugged process and renders the bitmap in the debugger.

Figure 1. Bitmap RenderingOutput window message filteringWhen checking build results, you can filter messages by message type to quickly locate messages of interest.

Figure 2. Filter Build MessagesHierarchical parent settingThe activity parent can now be set in the Activity Wizard when creating a new activity. Setting a hierarchal parent sets the Up button to automatically appear in the app's Action bar when viewing a child activity, so the Up button no longer needs to be manually specified in the menu.xml file.Creating layoutsAndroid Studio offers an advanced layout editor that allows you to drag-and-drop widgets into your layout and preview your layout while editing the XML.While editing in the Text view, you can preview the layout on devices by opening the Preview pane available on the right side of the window. Within the Preview pane, you can modify the preview by changing various options at the top of the pane, including the preview device, layout theme, platform version and more. To preview the layout on multiple devices simultaneously, select Preview All Screen Sizes from the device drop-down.

Figure 3. Preview All ScreensYou can switch to the graphical editor by clicking Design at the bottom of the window. While editing in the Design view, you can show and hide the widgets available to drag-and-drop by clicking Palette on the left side of the window. Clicking Designer on the right side of the window reveals a panel with a layout hierarchy and a list of properties for each view in the layout.Working with IntelliJ

This section list just a few of the code editing practices you should consider using when creating Android Studio apps. For complete user documentation for the IntelliJ IDEA interface (upon which Android Studio is based), refer to the IntelliJ IDEA documentation.External annotationsSpecify annotations within the code or from an external annotation file. The Android Studio IDE keeps track of the restrictions and validates compliance, for example setting the data type of a string as not null.Alt + Enter key bindingFor quick fixes to coding errors, the IntelliJ powered IDE implements the Alt + Enter key binding to fix errors (missing imports, variable assignments, missing references, etc) when possible, and if not, suggest the most probable solution. Ctrl + D key bindingThe Ctrl + D key binding is great for quickly duplicating code lines or fragments. Simply select the desired line or fragment and enter this key binding. Navigate menuIn case you're not familiar with an API class, file or symbol, the Navigate menu lets you jump directly to the class of a method or field name without having to search through individual classes. Inspection scopesScopes set the color of code segments for easy code identification and location. For example, you can set a scope to identify all code related to a specific action bar. External annotationsSpecify annotations within the code or from an external annotation file. The Android Studio IDE keeps track of the restrictions and validates compliance, for example setting the data type of a string as not null.Injecting languagesWith language injection, the Android Studio IDE allows you to work with islands of different languages embedded in the source code. This extends the syntax, error highlighting and coding assistance to the embedded language. This can be especially useful for checking regular expression values inline, and validating XML and SQL statments.Code foldingThis allows you to selectively hide and display sections of the code for readability. For example, resource expressions or code for a nested class can be folded or hidden in to one line to make the outer class structure easier to read. The inner clas can be later expanded for updates. Image and color previewWhen referencing images and icons in your code, a preview of the image or icon appears (in actual size at different densities) in the code margin to help you verify the image or icon reference. Pressing F1 with the preview image or icon selected displays resource asset details, such as the dp settings. Quick F1 documentationYou can now inspect theme attributes using View > Quick Documentation (F1), see the theme inheritance hierarchy, and resolve values for the various attributes.If you invoke View > Quick Documentation (usually bound to F1) on the theme attribute ?android:textAppearanceLarge, you will see the theme inheritance hierarchy and resolved values for the various attributes that are pulled in.New Allocation Tracker integration in the Android/DDMS windowYou can now inspect theme attributes using View > Quick Documentation F1, see the theme inheritance hierarchy, and resolved values for the various attributes.

Figure 4. Allocation TrackerKeyboard CommandsThe following tables list keyboard shortcuts for common operations.Note: This section lists Android Studio keyboard shortcuts for the default keymap. To change the default keymap on Windows and Linux, go to File > Settings > Keymap. To change the default keymap on Mac OS X, go to Android Studio > Preferences > Keymap.Note: If you're using Mac OS X, update your keymap to use the Mac OS X 10.5+ version keymaps under Android Studio > Preferences > Keymap.Table 1. Programming key commandsActionAndroid Studio Key Command

Command look-up (autocomplete command name)CTRL + SHIFT + A

Project quick fixALT + ENTER

Reformat codeCTRL + ALT + L (Win)OPTION + CMD + L (Mac)

Show docs for selected APICTRL + Q (Win)F1 (Mac)

Show parameters for selected methodCTRL + P

Generate methodALT + Insert (Win)CMD + N (Mac)

Jump to sourceF4 (Win)CMD + down-arrow (Mac)

Delete lineCTRL + Y (Win)CMD + Backspace (Mac)

Search by symbol nameCTRL + ALT + SHIFT + N (Win)OPTION + CMD + O (Mac)

Table 2. Project and editor key commandsActionAndroid Studio Key Command

BuildCTRL + F9 (Win)CMD + F9 (Mac)

Build and runSHIFT + F10 (Win)CTRL + R (Mac)

Toggle project visibilityALT + 1 (Win)CMD + 1 (Mac)

Navigate open tabsALT + left-arrow; ALT + right-arrow (Win)CTRL + left-arrow; CTRL + right-arrow (Mac)

For a complete keymap reference guide, see the IntelliJ IDEA documentation.Except as noted, this content is licensed under Creative Commons Attribution 2.5. For details and restrictions, see the Content License. About Android| Legal| Support

Developer WorkflowTo develop apps for Android, you use a set of tools that are included in Android Studio. In addition to using the tools from Android Studio, you can also access most of the SDK tools from the command line. Developing with Android Studio is the preferred method because it can directly invoke the tools that you need while developing applications.However, you may choose to develop with another IDE or a simple text editor and invoke the tools on the command line or with scripts. This is a less streamlined way to develop because you will sometimes have to call command line tools manually, but you will have access to the same number of features that you would have in Android Studio.

Figure 1. The development process for Android applications. App Workflow

The basic steps for developing applications (with or without Android Studio) are shown in figure 1. The development steps encompass four development phases, which include: Environment Setup During this phase you install and set up your development environment. You also create Android Virtual Devices (AVDs) and connect hardware devices on which you can install your applications.See Managing Virtual Devices and Using Hardware Devices for more information. Project Setup and Development During this phase you set up and develop your Android Studio project and application modules, which contain all of the source code and resource files for your application. For more information, see Create an Android project. Building, Debugging and Testing During this phase you build your project into a debuggable .apk package(s) that you can install and run on the emulator or an Android-powered device. Android Studio uses a build system based on Gradle that provides flexibility, customized build variants, dependency resolution, and much more. If you're using another IDE, you can build your project using Gradle and install it on a device using adb. For more information, see Build and run your application.Next, with Android Studio you debug your application using the Android Debug Monitor and device log messages (logact) along with the IntelliJ IDEA intelligent coding features. You can also use a JDWP-compliant debugger along with the debugging and logging tools that are provided with the Android SDK. For more information see Debug your application with the SDK debugging and logging tools.Last, you test your application using various Android SDK testing tools. For more information, see Test your application with the Testing and Instrumentation framework. Publishing During this phase you configure and build your application for release and distribute your application to users. For more information, see Publishing Overview.Essential command line tools

When developing in IDEs or editors other than Android Studio, be familiar with all of the tools below, because you will have to run them from the command line or script.androidCreate and update Android projects and create, move, and delete AVDs.Android EmulatorRun your Android applications on an emulated Android platform.Android Debug BridgeInterface with your emulator or connected device (install apps, shell the device, issue commands, etc.).In addition to the above tools that are included with the SDK, you need the following open source and third-party tools:Gradle To compile and build your Android project into an installable .apk file(s).KeytoolTo generate a keystore and private key, used to sign your .apk file. Keytool is part of the JDK.Jarsigner (or similar signing tool)To sign your .apk file with a private key generated by Keytool. Jarsigner is part of the JDK.If you are using Android Studio, tools such as adb and android are automatically called by Android Studio so you don't have to manually invoke these tools. You need to be familiar with adb, however, because certain functions are not accessible from Android Studio, such as the adb shell commands. You might also need to call Keytool and Jarsigner to sign your applications, but you can set up Android Studio to do this automatically as well.For more information on the tools provided with the Android SDK, see the Tools section of the documentation.Except as noted, this content is licensed under Creative Commons Attribution 2.5. For details and restrictions, see the Content License. About Android| Legal| Support

Managing Virtual DevicesAn Android Virtual Device (AVD) is an emulator configuration that lets you model an actual device by defining hardware and software options to be emulated by the Android Emulator.The easiest way to create an AVD is to use the graphical AVD Manager, which you launch from Eclipse by clicking Window > AVD Manager. You can also start the AVD Manager from the command line by calling the android tool with the avd options, from the /tools/ directory.You can also create AVDs on the command line by passing the android tool options. For more information on how to create AVDs in this manner, see Managing Virtual Devices from the Command Line.An AVD consists of: A hardware profile: Defines the hardware features of the virtual device. For example, you can define whether the device has a camera, whether it uses a physical QWERTY keyboard or a dialing pad, how much memory it has, and so on. A mapping to a system image: You can define what version of the Android platform will run on the virtual device. You can choose a version of the standard Android platform or the system image packaged with an SDK add-on. Other options: You can specify the emulator skin you want to use with the AVD, which lets you control the screen dimensions, appearance, and so on. You can also specify the emulated SD card to use with the AVD. A dedicated storage area on your development machine: the device's user data (installed applications, settings, and so on) and emulated SD card are stored in this area.You can create as many AVDs as you need, based on the types of device you want to model. To thoroughly test your application, you should create an AVD for each general device configuration (for example, different screen sizes and platform versions) with which your application is compatible and test your application on each one.Keep these points in mind when you are selecting a system image target for your AVD: The API Level of the target is important, because your application will not be able to run on a system image whose API Level is less than that required by your application, as specified in the minSdkVersion attribute of the application's manifest file. For more information about the relationship between system API Level and application minSdkVersion, see Specifying Minimum System API Version. You should create at least one AVD that uses a target whose API Level is greater than that required by your application, because it allows you to test the forward-compatibility of your application. Forward-compatibility testing ensures that, when users who have downloaded your application receive a system update, your application will continue to function normally. If your application declares a uses-library element in its manifest file, the application can only run on a system image in which that external library is present. If you want to run your application on an emulator, create an AVD that includes the required library. Usually, you must create such an AVD using an Add-on component for the AVD's platform (for example, the Google APIs Add-on contains the Google Maps library).To learn how to manage AVDs using a graphical tool, read Managing AVDs with AVD Manager. To learn how to manage AVDs on the command line, read Managing AVDs from the Command Line.Managing AVDs with AVD ManagerIn this document1. Creating an AVD 1. Creating a device definition2. Hardware options2. Creating Emulator SkinsThe AVD Manager is a tool you can use to create and manage Android virtual devices (AVDs), which define device configurations for the Android Emulator.To launch the AVD Manager: In Android Studio, select Tools > Android > AVD Manager, or click the AVD Manager icon in the toolbar. Or, use the command line to navigate to your SDK's tools/ directory and execute: $ android avdThe AVD Manager main screen shows your current virtual devices, as shown in figure 1.

Figure 1. The AVD Manager main screen shows your current virtual devices.Note: If you launch the AVD Manager from the command line, the UI is different than how it appears in Android Studio, as documented here. Most of the same functionality is available, but the command-line version of the AVD Manager is currently not documented.Creating an AVD

You can create as many AVDs as you would like to use with the Android Emulator. To effectively test your app, you should create an AVD that models each device type for which you have designed your app to support. For instance, you should create an AVD for each API level equal to and higher than the minimum version you've specified in your manifest tag.To create an AVD based on an existing device definition:1. From the main screen (figure 1), click Create Virtual Device.2. In the Select Hardware window, select a device configuration, such as Nexus 6, then click Next.

Figure 2. The Select Hardware window.3. Select the desired system version for the AVD and click Next. 4. Verify the configuration settings, then click Finish. If necessary, click Show Advanced Settings to select a custom skin for the hardware profile and adjust other hardware settings.To launch the AVD in the Android Emulator, click the launch button in the list of AVDs.Creating a device definitionIn case the available device definitions do not match the device type you'd like to emulate, you can create a custom device definition for your AVD:1. From the main screen (figure 1), click Create Virtual Device.2. To begin you custom device by using an existing device profile as a template, select a device profile then click Clone Device. Or, to start from scratch, click New Hardware Profile.3. The following Configure Hardware Profile window (figure 3) allows you to specify various configurations such as the screen size, memory options, input type, and sensors.When you're done configuring the device, click Finish.

Figure 3. The Configure Hardware window when creating a custom device configuration.4. Your custom device configuration is now available in the list of device definitions (shown after you click Create Virtual Device). To continue preparing an AVD with your custom device configuration, select the new configuration and follow the instructions above to create an AVD with an existing device definition (and select your new definition).Hardware optionsIf you are creating a new AVD, you can specify the following hardware options for the AVD to emulate:CharacteristicDescriptionProperty

Device ram sizeThe amount of physical RAM on the device, in megabytes. Default value is "96".hw.ramSize

Touch-screen supportWhether there is a touch screen or not on the device. Default value is "yes".hw.touchScreen

Trackball supportWhether there is a trackball on the device. Default value is "yes".hw.trackBall

Keyboard supportWhether the device has a QWERTY keyboard. Default value is "yes".hw.keyboard

DPad supportWhether the device has DPad keys. Default value is "yes".hw.dPad

GSM modem supportWhether there is a GSM modem in the device. Default value is "yes".hw.gsmModem

Camera supportWhether the device has a camera. Default value is "no".hw.camera

Maximum horizontal camera pixelsDefault value is "640".hw.camera.maxHorizontalPixels

Maximum vertical camera pixelsDefault value is "480".hw.camera.maxVerticalPixels

GPS supportWhether there is a GPS in the device. Default value is "yes".hw.gps

Battery supportWhether the device can run on a battery. Default value is "yes".hw.battery

AccelerometerWhether there is an accelerometer in the device. Default value is "yes".hw.accelerometer

Audio recording supportWhether the device can record audio. Default value is "yes".hw.audioInput

Audio playback supportWhether the device can play audio. Default value is "yes".hw.audioOutput

SD Card supportWhether the device supports insertion/removal of virtual SD Cards. Default value is "yes".hw.sdCard

Cache partition supportWhether we use a /cache partition on the device. Default value is "yes".disk.cachePartition

Cache partition sizeDefault value is "66MB".disk.cachePartition.size

Abstracted LCD densitySets the generalized density characteristic used by the AVD's screen. Default value is "160".hw.lcd.density

Creating Emulator Skins

An Android emulator skin is a collection of files that define the visual and control elements of an emulator display. If the skin definitions available in the AVD settings don't meet your needs, you can create your own custom skin definition, then apply it to your AVD from the advanced settings on the Verify Configuration screen.Each emulator skin contains: A hardware.ini file Layout files for supported orientations (landscape, portrait) and physical configuration Image files for display elements, such as background, keys and buttonsTo create and use a custom skin:1. Create a new directory where you will save your skin configuration files. 2. Define the visual appearance of the skin in a text file named layout. This file defines many characteristics of the skin, such as the size and image assets for specific buttons. For example: parts { device { display { width 320 height 480 x 0 y 0 } }

portrait { background { image background_port.png }

buttons { power { image button_vertical.png x 1229 y 616 } } } ...}3. Add the bitmap files of the device images in the same directory.4. Specify additional hardware-specific device configurations an hardware.ini file for the device settings, such as hw.keyboard and hw.lcd.density.5. Archive the files in the skin folder and select the archive file as a custom skin. For more detailed information about creating emulator skins, see the Android Emulator Skin File Specification in the tools source code.Managing AVDs from the Command LineIn this document1. Listing Targets2. Creating AVDs 1. Customize the device resolution or density2. Default location of AVD files3. Setting hardware emulation options3. Moving an AVD4. Updating an AVD5. Deleting an AVDSee also1. Building and Running from the Command Line2. Using the Android EmulatorThe android tool lets you manage AVDs on the command line. For a complete reference of the command line options that you can use, see the reference for the android tool.Listing Targets

To generate a list of system image targets, use this command: android list targetsThe android tool scans the /platforms/ and /add-ons/ directories looking for valid system images and then generates the list of targets. Here's an example of the command output: Available Android targets:id: 1 or "android-3" Name: Android 1.5 Type: Platform API level: 3 Revision: 4 Skins: QVGA-L, HVGA-L, HVGA (default), HVGA-P, QVGA-Pid: 2 or "android-4" Name: Android 1.6 Type: Platform API level: 4 Revision: 3 Skins: QVGA, HVGA (default), WVGA800, WVGA854id: 3 or "android-7" Name: Android 2.1-update1 Type: Platform API level: 7 Revision: 2 Skins: QVGA, WQVGA400, HVGA (default), WVGA854, WQVGA432, WVGA800id: 4 or "android-8" Name: Android 2.2 Type: Platform API level: 8 Revision: 2 Skins: WQVGA400, QVGA, WVGA854, HVGA (default), WVGA800, WQVGA432id: 5 or "android-9" Name: Android 2.3 Type: Platform API level: 9 Revision: 1 Skins: HVGA (default), WVGA800, WQVGA432, QVGA, WVGA854, WQVGA400Creating AVDs

In addition to creating AVDs with the AVD Manager user interface, you can also create them by passing in command line arguments to the android tool. Open a terminal window and change to the /tools/ directory, if needed.To create each AVD, you issue the command android create avd, with options that specify a name for the new AVD and the system image you want to run on the emulator when the AVD is invoked. You can specify other options on the command line also, such as the emulated SD card size, the emulator skin, or a custom location for the user data files.Here's the command-line usage for creating an AVD: android create avd -n -t [- ] ... You can use any name you want for the AVD, but since you are likely to be creating multiple AVDs, you should choose a name that lets you recognize the general characteristics offered by the AVD. The target ID is an integer assigned by the android tool. The target ID is not derived from the system image name, version, or API Level, or other attribute, so you need to run the android list targets command to list the target ID of each system image. You should do this before you run the android create avd command. See the android tool documentation for more information on the command line options.When you've selected the target you want to use and made a note of its ID, use the android create avd command to create the AVD, supplying the target ID as the -t argument. Here's an example that creates an AVD with name "my_android1.5" and target ID "2" (the standard Android 1.5 system image in the list above): android create avd -n my_android1.5 -t 2If the target you selected was a standard Android system image ("Type: platform"), the android tool next asks you whether you want to create a custom hardware profile. Android 1.5 is a basic Android platform.Do you wish to create a custom hardware profile [no]If you want to set custom hardware emulation options for the AVD, enter "yes" and set values as needed. If you want to use the default hardware emulation options for the AVD, just press the return key (the default is "no"). The android tool creates the AVD with name and system image mapping you requested, with the options you specified. For more information, see Setting Hardware Emulation Options. Note: If you are creating an AVD whose target is an SDK add-on, the android tool does not allow you to set hardware emulation options. It assumes that the provider of the add-on has set emulation options appropriately for the device that the add-on is modeling, and so prevents you from resetting the options. Customize the device resolution or densityWhen testing your application, we recommend that you test your application in several different AVDs, using different screen configurations (different combinations of size and density). In addition, you should set up the AVDs to run at a physical size that closely matches an actual device.To set up your AVDs for a specific resolution or density, follow these steps:1. Use the create avd command to create a new AVD, specifying the --skin option with a value that references either a default skin name (such as "WVGA800") or a custom skin resolution (such as 240x432). Here's an example: android create avd -n -t --skin WVGA8002. To specify a custom density for the skin, answer "yes" when asked whether you want to create a custom hardware profile for the new AVD.3. Continue through the various profile settings until the tool asks you to specify "Abstracted LCD density" (hw.lcd.density). Enter an appropriate value, such as "120" for a low-density screen, "160" for a medium density screen, or "240" for a high-density screen.4. Set any other hardware options and complete the AVD creation.In the example above (WVGA medium density), the new AVD will emulate a 5.8" WVGA screen.As an alternative to adjusting the emulator skin configuration, you can use the emulator skin's default density and add the -dpi-device option to the emulator command line when starting the AVD. For example:emulator -avd WVGA800 -scale 96dpi -dpi-device 160Default location of AVD filesWhen you create an AVD, the android tool creates a dedicated directory for it on your development computer. The directory contains the AVD configuration file, the user data image and SD card image (if available), and any other files associated with the device. Note that the directory does not contain a system image instead, the AVD configuration file contains a mapping to the system image, which it loads when the AVD is launched. The android tool also creates an .ini file for the AVD at the root of the .android/avd/ directory on your computer. The file specifies the location of the AVD directory and always remains at the root the .android directory.By default, the android tool creates the AVD directory inside ~/.android/avd/ (on Linux/Mac), C:\Documents and Settings\\.android\ on Windows XP, and C:\Users\\.android\ on Windows 7 and Vista. If you want to use a custom location for the AVD directory, you can do so by using the -p option when you create the AVD: android create avd -n my_android1.5 -t 2 -p path/to/my/avdIf the .android directory is hosted on a network drive, we recommend using the -p option to place the AVD directory in another location. The AVD's .ini file remains in the .android directory on the network drive, regardless of the location of the AVD directory. Setting hardware emulation optionsWhen you are creating a new AVD that uses a standard Android system image ("Type: platform"), the android tool lets you set hardware emulation options for virtual device. The table below lists the options available and the default values, as well as the names of properties that store the emulated hardware options in the AVD's configuration file (the config.ini file in the AVD's local directory). Table 1. Available hardware profile options for AVDs and the default values CharacteristicDescriptionProperty

Device ram sizeThe amount of physical RAM on the device, in megabytes. Default value is "96". hw.ramSize

Touch-screen supportWhether there is a touch screen or not on the device. Default value is "yes".hw.touchScreen

Trackball support Whether there is a trackball on the device. Default value is "yes".hw.trackBall

Keyboard supportWhether the device has a QWERTY keyboard. Default value is "yes".hw.keyboard

DPad supportWhether the device has DPad keys. Default value is "yes".hw.dPad

GSM modem supportWhether there is a GSM modem in the device. Default value is "yes".hw.gsmModem

Camera supportWhether the device has a camera. Default value is "no".hw.camera

Maximum horizontal camera pixelsDefault value is "640".hw.camera.maxHorizontalPixels

Maximum vertical camera pixelsDefault value is "480".hw.camera.maxVerticalPixels

GPS supportWhether there is a GPS in the device. Default value is "yes".hw.gps

Battery supportWhether the device can run on a battery. Default value is "yes".hw.battery

AccelerometerWhether there is an accelerometer in the device. Default value is "yes".hw.accelerometer

Audio recording supportWhether the device can record audio. Default value is "yes".hw.audioInput

Audio playback supportWhether the device can play audio. Default value is "yes".hw.audioOutput

SD Card supportWhether the device supports insertion/removal of virtual SD Cards. Default value is "yes".hw.sdCard

Cache partition supportWhether we use a /cache partition on the device. Default value is "yes".disk.cachePartition

Cache partition sizeDefault value is "66MB".disk.cachePartition.size

Abstracted LCD densitySets the generalized density characteristic used by the AVD's screen. Default value is "160".hw.lcd.density

Trackball supportWhether there is a trackball present.hw.trackBall

Moving an AVD

If you want to move or rename an AVD, you can do so using this command:android move avd -n [- ] ...Updating an AVD

If, for any reason, the platform/add-on root folder has its name changed (maybe because the user has installed an update of the platform/add-on) then the AVD will not be able to load the system image that it is mapped to. In this case, the android list targets command will produce this output: The following Android Virtual Devices could not be loaded: Name: foo Path: /.android/avd/foo.avd Error: Invalid value in image.sysdir. Run 'android update avd -n foo' To fix this error, use the android update avd command to recompute the path to the system images.Deleting an AVD

You can use the android tool to delete an AVD. Here is the command usage:android delete avd -n When you issue the command, the android tool looks for an AVD matching the specified name deletes the AVD's directory and files. Using the EmulatorIn this document1. Overview2. Android Virtual Devices and the Emulator3. Starting and Stopping the Emulator4. Installing Applications on the Emulator5. Using Hardware Acceleration 1. Configuring Graphics Acceleration2. Configuring Virtual Machine Acceleration6. SD Card Emulation 1. Creating an SD card image2. Copying files to an SD card image3. Loading an SD card image7. Working with Emulator Disk Images 1. Default image files2. Runtime images: user data and SD card3. Temporary images8. Emulator Networking 1. Network Address Space2. Local Networking Limitations3. Using Network Redirection4. Configuring the Emulator's DNS Settings5. Using the Emulator with a Proxy6. Interconnecting Emulator Instances7. Sending a Voice Call or SMS to Another Emulator Instance9. Using the Emulator Console 1. Port Redirection2. Geo Location Provider Emulation3. Hardware Events Emulation4. Device Power Characteristics5. Network Status6. Network Delay Emulation7. Network Speed Emulation8. Telephony Emulation9. SMS Emulation10. VM State11. Emulator Window12. Terminating an Emulator Instance10. Emulator Limitations11. Troubleshooting Emulator ProblemsSee also1. Android Emulator2. Managing AVDs with AVD ManagerThe 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.Android Virtual Devices and the Emulator

To use the emulator, you first must create one or more AVD configurations. In each configuration, you specify an Android platform to run in the emulator and the set of hardware options and emulator skin you want to use. Then, when you launch the emulator, you specify the AVD configuration that you want to load. Each AVD functions as an independent device, with its own private storage for user 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 tool that 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 your application in the Android emulator. You can launch the emulator as a standalone application from a command line, or you can run it from within your Android Studio development environment. In either case, you specify the AVD configuration to load 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 your application in more than one emulated device. You can use the emulator's built-in commands to simulate GSM phone calling or SMS between emulator instances, and you can set up network redirection that allows emulators to send data to one another. For more information, see Telephony Emulation, SMS Emulation, and Emulator NetworkingTo start an instance of the emulator from the command line, navigate to the tools/ folder of the SDK. Enter emulator command like this: emulator -avd []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.When you run your app from Android Studio, it installs and launches the app on your connected device or emulator (launching the emulator, if necessary). 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 Android Studio, 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.Installing Applications on the Emulator

If you don't have access to Android Studio, 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.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 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.Using Hardware Acceleration

In order to make the Android emulator run faster and be more responsive, you can configure it to take advantage of hardware acceleration, using a combination of configuration options, specific Android system images and hardware drivers.Configuring Graphics AccelerationCaution: As of SDK Tools Revision 17, the graphics acceleration feature for the emulator is experimental; be alert for incompatibilities and errors when using this feature. 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. To use the graphics acceleration feature, you must have the following versions of the Android development tools installed: Android SDK Tools, Revision 17 or higher Android SDK Platform API 15, Revision 3 or higherUse the Android SDK Manager to install these components:Note: Not all applications are compatible with graphics hardware acceleration. 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:1. Make sure you have the required SDK components installed (listed above).2. Start the AVD Manager and create a new AVD with the Target value of Android 4.0.3 (API Level 15), revision 3 or higher.3. If you want to have graphics acceleration enabled by default for this AVD, in the Hardware section, click New, select GPU emulation and set the value to Yes. Note: You can also enable graphics acceleration when you start an emulator using command line options as describe in the next section.4. Name the AVD instance and select any other configuration options. Caution: Do not select the Snapshot: Enabled option. Snapshots are not supported for emulators with graphics acceleration enabled.5. Click Create AVD to save the emulator configuration.If you set GPU emulation to Yes for your AVD, then graphics acceleration is automatically enabled when you run it. If you did not enable GPU emulation 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: emulator -avd -gpu onNote: 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 Android Studio, run your Android application using an AVD with the -gpu on option enabled: 1. In Android Studio, click your Android application module folder and then select Run > Edit Configurations...2. In the left panel of the Run/Debug Configurations dialog, select your Android run configuration or create a new configuration.3. Under the Target Device options, select the AVD you created in the previous procedure.4. In the Emulator tab, in the Additional command line options field, enter:-gpu on5. Run your Android project using this run configuration.Configuring Virtual Machine AccelerationCaution: As of SDK Tools Revision 17, the virtual machine acceleration feature for the emulator is experimental; be alert for incompatibilities and errors when using this feature.Many modern CPUs provide extensions for running virtual machines (VMs) more efficiently. Taking advantage of these extensions with the Android emulator requires some additional configuration of your development system, but can significantly improve the execution speed. Before attempting to use this type of acceleration, you should first determine if your development systems CPU supports one of 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 supports virtualization 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 through your computer's BIOS and are frequently turned off by default. Check the documentation for your system's motherboard to find out how to enable virtualization extensions.Once you have determined that your CPU supports virtualization extensions, make sure you can work within these additional requirements of running an emulator inside an accelerated virtual machine: 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 configurations described here. Not Inside a VM - You cannot run a VM-accelerated emulator inside another virtual machine, such as a VirtualBox or VMWare-hosted virtual machine. You must run the emulator directly on your system hardware. Other VM Drivers - If you are running another virtualization technology on your system such as VirtualBox or VMWare, you may need to unload the driver for that virtual machine hosting software before running an accelerated emulator. OpenGL Graphics - Emulation of OpenGL ES graphics may not perform at the same level as an actual device.To use virtual machine acceleration with the emulator, you need the following version of Android development tools. Use the Android SDK Manager to install these components: Android SDK Tools, Revision 17 or higher Android x86-based system imageIf your development environment meets all of the requirements for running a VM-accelerated emulator, you can use the AVD Manager to create an x86-based AVD configuration:1. 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.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 WindowsVirtual 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 /extras/intel/Hardware_Accelerated_Execution_Manager/IntelHAXM.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 intelhaxmYou should see a status message including the following information:SERVICE_NAME: intelhaxm ... STATE : 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 Note: You must provide an x86-based AVD configuration name, otherwise VM acceleration will not be enabled. If you are running the emulator from Android Studio, run your Android application with an x86-based AVD: 1. In Android Studio, click your Android project folder and then select Run > Edit Configurations...2. In the left panel of the Run/Debug Configurations dialog, select your Android run configuration or create a new configuration.3. Under the Target Device options, select the x86-based AVD you created previously.4. 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 MacVirtual 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 /extras/intel/Hardware_Accelerated_Execution_Manager/IntelHAXM.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 intelYou should see a status message containing the following extension name, indicating that the kernel extension is loaded:com.intel.kext.intelhaxmTo 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 Note: You must provide an x86-based AVD configuration name, otherwise VM acceleration will not be enabled. If you are running the emulator from Andriod Studio, run your Android application with an x86-based AVD: 1. In Android Studio, click your Android module folder and then select Run > Edit Configurations...2. In the left panel of the Run/Debug Configurations dialog, select your Android run configuration or create a new configuration.3. Under the Target Device options, select the x86-based AVD you created previously.4. 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.shConfiguring VM Acceleration on LinuxLinux-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 -qemu -m 512 -enable-kvmNote: You must provide an x86-based AVD configuration name, otherwise VM acceleration will not be enabled. If you are running the emulator from Android Studio, run your Android application with an x86-based AVD and include the KVM options: 1. In Android Studio, click your Android module folder and then select Run > Edit Configurations...2. In the left panel of the Run/Debug Configurations dialog, select your Android run configuration or create a new configuration.3. Under the Target Device options, select the x86-based AVD you created previously.4. In the Emulator tab, in the Additional command line options field, enter: -qemu -m 512 -enable-kvm5. 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.Creating an SD card imageThere 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 create avd -n -t -c [K|M]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 For example:mksdcard 1024M sdcard1.isoFor more information, see mksdcard.Copying files to an SD card imageOnce you have created the disk image, you can copy files to it prior to loading it in the emulator. To copy files, you can mount the image as a loop device and then copy the files to it, or you can use a utility such as mtools to copy 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 image while it is loaded in an emulator. For more information see the adb push documentation.Loading an SD card imageBy default, the emulator loads the SD card image that is stored with the active AVD (see the -avd startup option).Alternatively, you can start the emulator with the -sdcard flag and specify the name and path of your image (relative to the current working directory): emulator -sdcard Working with Emulator Disk Images

The emulator uses mountable disk images stored on your development machine to simulate flash (or similar) partitions on an actual device. For example, it uses a disk image containing an emulator-specific kernel, the Android system, a ramdisk image, and writeable images for user data and simulated SD card.To run properly, the emulator requires access to a specific set of disk image files. By default, the Emulator always looks for the disk images in the private storage area of the AVD in use. If no images exist there when the Emulator is launched, it creates the images in the AVD directory based on default versions stored in the SDK. Note: The default storage location for AVDs is in ~/.android/avd on OS X and Linux, C:\Documents and Settings\\.android\ on Windows XP, and C:\Users\\.android\ on Windows Vista.To let you use alternate or custom versions of the image files, the emulator provides startup options that override the default locations and filenames of the image files. When you use one of these options, the emulator searches for the image file under the image name or location that you specify; if it can not locate the image, it reverts to using the default names and location.The emulator uses three types of image files: default image files, runtime image files, and temporary image files. The sections below describe how to override the location/name of each type of file. Default image filesWhen the emulator launches, but does not find an existing user data image in the active AVD's storage area, it creates a new one from a default version included in the SDK. The default user data image is read-only. The image files are read-only.The emulator provides the -system 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 ). NameDescriptionComments

userdata.imgThe initial user-data disk imageOverride using -initdata . Also see -data , below.

Runtime images: user data and SD cardAt runtime, the emulator reads and writes data to two disk images: a user-data image and (optionally) an SD card image. These images emulate the user-data partition and removable storage media on actual device. The emulator provides a default user-data disk image. At startup, the emulator creates 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 storage locations of the runtime images to load, as described in the following table. When you use one of 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). NameDescriptionComments

userdata-qemu.imgAn image to which the emulator writes runtime user-data for a unique user.Override using -data , where is the path 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 does not exist, the emulator creates an image from the default userdata.img, stores it under the name you specified, and persists user data to it at shutdown.

sdcard.imgAn image representing an SD card inserted into the emulated device.Override using -sdcard , where is the path 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 ImageEach 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 CardOptionally, 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 EmulationYou 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 ImagesThe 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 imageThe emulator does not permit renaming the temporary system image or persisting it at device power-off. 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 , which specifies the name of the file in which to persist the /cache image at device power-off. If 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. Network Address SpaceEach instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine's network interfaces and settings and from the internet. An emulated device can not see your development machine or other emulator instances on the network. Instead, it sees only that it is connected through Ethernet to a router/firewall.The virtual router for each instance manages the 10.0.2/24 network address space all addresses managed by the router are in the form of 10.0.2., where is a number. Addresses within this space are pre-allocated by the emulator/router as follows:Network AddressDescription

10.0.2.1Router/gateway address

10.0.2.2Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)

10.0.2.3First DNS server

10.0.2.4 / 10.0.2.5 / 10.0.2.6Optional second, third and fourth DNS server (if any)

10.0.2.15The emulated device's own network/ethernet interface

127.0.0.1The 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)Local Networking LimitationsAndroid applications running in an emulator can connect to the network available on your workstation. However, they connect through the emulator, not directly to hardware, and the emulator acts like a normal application on your workstation. This means that the emulator, and thus your Android applications, are subject to some limitations: Communication with the emulated device may be blocked by a firewall program 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 and UDP connections/messages on behalf of the emulated device, provided your development machine's network environment allows it to do so. There are no built-in limitations on port numbers or ranges except the one imposed by your host operating system and network.Depending on the environment, the emulator may not be able to support other protocols (such as ICMP, used for "ping") might not be supported. Currently, the emulator does not support IGMP or multicast. Using Network RedirectionTo communicate with an emulator instance behind its virtual router, you need to set up network redirection on the virtual router. Clients can then connect to a specified guest port on the router, while the router directs traffic to/from that port to the emulated device's host port. To set up the network redirection, you create a mapping of host and guest ports/addresses on the emulator instance. There are two ways to set up network redirection: using emulator console commands and using the ADB tool, as described below. Setting up Redirection through the Emulator ConsoleEach emulator instance provides a control console the you can connect to, to issue commands that are specific to that instance. You can use the redir console command to set up redirection as needed for an emulator instance. First, determine the console port number for the target emulator instance. For example, the console port number for the first emulator instance launched is 5554. Next, connect to the console of the target emulator instance, specifying its console port number, as follows: telnet localhost 5554Once connected, use the redir command to work with redirection. To add a redirection, use:add ::where is either tcp or udp, and and 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:6000To 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 ADBThe 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.Configuring the Emulator's DNS SettingsAt startup, the emulator reads the list of DNS servers that your system is currently using. It then stores the IP addresses of up to four servers on this list 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 parsing the file /etc/resolv.conf. On Windows, the emulator obtains the addresses by calling the GetNetworkParams() API. Note that this usually 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 option to manually specify the addresses of DNS servers to use, where is a comma-separated list of server names or IP addresses. You might find this option useful if you encounter 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 ProxyIf your emulator must access the Internet through a proxy server, you can use the -http-proxy option when starting the emulator, to set up the appropriate redirection. In this case, you specify proxy information in in one of these formats:http://:orhttp://:@: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 . In this case, you do not need to specify a value for 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.Interconnecting Emulator InstancesTo allow one emulator instance to communicate with another, you must set up the 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 Aand you want to run a server on B, to which C will connect, here is how you could set it up: 1. Set up the server on B, listening to 10.0.2.15:2. On B's console, set up a redirection from A:localhost: to B:10.0.2.15:3. On C, have the client connect to 10.0.2.2:For example, if you wanted to run an HTTP server, you can select as 80 and as 8080: 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:8080Sending a Voice Call or SMS to Another Emulator InstanceThe emulator automatically forwards simulated voice calls and SMS messages from one instance to another. 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:1. Launch the dialer application on the originating emulator instance.2. 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 (). 3. 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 emulated device environment. For example, you can use the console to manage port redirection, network characteristics, and telephony events while your application is running on the emulator. To access 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: telnet localhost 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 RedirectionYou 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 The redir command supports the subcommands listed in the table below. Subcommand DescriptionComments

listList the current port redirection.

add::Add a new port redirection. must be either "tcp" or "udp" is the port number to open on the host is the port number to route data to on the emulator/device

del :Delete a port redirection.The meanings of and are listed in the previous row.

Geo Location Provider EmulationYou can use the console to set the geographic location reported to the applications running inside an emulator. Use the geo command to send a simple GPS fix to the emulator, with or without NMEA 1083 formatting:geo The geo command supports the subcommands listed in the table below.SubcommandDescriptionComments

fix []Send a simple GPS fix to the emulator instance.Specify longitude and latitude in decimal degrees. Specify altitude in meters.

nmea Send an NMEA 0183 sentence to the emulated device, as if it were sent from an emulated GPS modem. 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. 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")For more information about the Location Manager, see LocationManager. Hardware Events EmulationThe event console commands sends hardware events to the emulator. The syntax for this command is as follows:event The event command supports the subcommands listed in the table below. Subcommand DescriptionComments

send :: [...]Send one or more events to the Android kernel. You can use text names or integers for and .

typesList all string aliases supported by the event subcommands.

codes List all string aliases supported by the event subcommands for the specified .

event text 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 CharacteristicsThe power command controls the power state reported by the emulator to applications. The syntax for this command is as follows: power The event command supports the subcommands listed in the table below. Subcommand DescriptionComments

displayDisplay battery and charger state.

ac Set AC charging state to on or off.

status Change battery status as specified.

present Set battery presence state.

health Set battery health state.

capacity Set remaining battery capacity state (0-100).

Network StatusYou 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. H