Android Emulator Apple Silicon Preview

This document gives you some background on the emulator and outlines how you can start hacking and contributing to the emulator!

Just get me started with development!

Make sure to install Android Studio and the associated SDKs. Do not forget to install the official emulator and create a few android virtual devices. Next follow the instructions for the platform you would like to work on:

We use the Repo tool to manage working accross multiple branches.

About the Emulator

Google has introduced an Android emulator for Apple's new ARM-based Macs. Google emphasizes that the emulator is a first preview. The latest release of Android Studio focuses on three main areas, says Google: improving UI design, extending device support, and boosting developer productivity. Additionally, Android Studio Arctic F. Create AVD of Android N Preview for Android Emulator, in Android Studio.

The Android Emulator simulates Android devices on your computer so that you can test your application on a variety of devices and Android API levels without needing to have each physical device.

Want to Emulate android apps and games on your PC/Laptop, then download top 12 Android Emulators on your Windows PC/Laptop.

The emulator provides almost all of the capabilities of a real Android device. You can simulate incoming phone calls and text messages, specify the location of the device, simulate different network speeds, simulate rotation and other hardware sensors, access the Google Play Store, and much more.

Testing your app on the emulator is in some ways faster and easier than doing so on a physical device. For example, you can transfer data faster to the emulator than to a device connected over USB.

The emulator comes with predefined configurations for various Android phone, tablet, Wear OS, and Android TV devices.

Recommended Reading

The following is a list of concepts that are important. Please read these links and any other links you can find. If you find a link that you think does a better job at explaining the concept, please add it here:

QEMU is an open source competitor to VMware Workstation, VirtualBox, HyperV. It is focused on Linux server virtualization on Linux servers. While QEMU does support booting other OS’s, we don’t use that functionality since Android is Linux.

The Android Emulator is downstream from the QEMU emulator. It adds support for booting Android devices, emulates typical Android hardware (OpenGL, GPS, GSM, Sensors) and a GUI interface. The android emulator extends qemu in various ways.

For an overview of Qemu see:

The QEMU emulator leverages technologies like hardware Hypervisors KVM (Linux) and HAXM (Windows/Mac)

The QEMU emulator supports both guest images that require full virtualization and guest images that require paravirtualization technologies like virtio

The emulator passes a device tree blob to a guest kernel to describe the guest hardware

When running a non-x86 image on an x86 host, QEMU will JIT the non-x86 code into x86 code. See this lectutre for more. The MMU (page table hardware) is emulated in software, which is unfortunately slow.

You will need to build Android kernels and system images that the emulator will run. The easiest way to obtain these is to make use of the publicly released images. You can find more details here.

Building the Emulator

The emulator uses Cmake as a meta build generator, and all the necessary compilers and toolchains are included in the repository. Make sure you have read the section above as the requirements to succesfully build vary slightly from platform to platform.

In general you can run the following script:

For incremental builds you can use ninja. For example

Contributing code

The emulator uses a coding style derived from the Chromium style. We use the repo tool to submit pathces. The usual workflow is roughly as follows:

This will create a git branch called my_awesome_feature. You can now work on your patch.

Once you have written a patch you can send it out for code review. We use gerrit for code reviews.

Use the repo tool to upload or update a CL:

  • “--cbr” means “upload the current branch”,
  • “--re” supplies the initial reviewers list

Add “-t” switch to use the current git branch as a review topic (topic groups CLs together and only allows them to be submitted when all got +2/+verified)

The repo tool will provide you with a url where you can find your change.

Code Reviews

Android Emulator Apple Silicon Preview Download

Make sure to check the CL against our coding style: coding style. Coding style isn’t frozen: just edit it in our repository and create a code review to propose a change.

Some good articles on code reviewing, especially when it comes to google:

  • The CL Author’s Guide, which gives detailed guidance to developers whose CLs are undergoing review.
  • How to Do a Code Review, which gives detailed guidance for code reviewers.

Below are some short notes relevant to the emulator.

Keep in mind that all of the code reviews are open source and visible to everyone!. In other words, be nice and and provide actionable constructive feedback.

  • C++ over C for all new code. Always.

  • After uploading a CL for review, author should “+1” it when they think it’s ready for reviewing. A CL without author’s “+1” is a “work in progress” and other reviewers may ignore it..

  • Prefer not to send a WIP CL to reviewers and only add them when it’s in a reviewable state. If you realized that you added reviewers too soon, just remove them - “x” button in the browser UI for each reviewer actually works.

  • Avoid large CLs. There are always exceptions, use your best judgement to improve code clarity and to help other maintainers in the future.

    Split the changes into smaller isolated chunks and submit those as a single topic If you touch multiple components, that’s a good way to split the CL.

    Changes into any QEMU files must be in their own CL - otherwise rebasing into the new version becomes 10x more painful.

  • “-2” is sticky, it remains there until the very same reviewer removes it. If you “-2”-ed someone, it’s always a good thing to communicate to them about the follow-up

  • Abandon the CLs you don’t need anymore

  • Tests: when reviewing the code, make sure there’s a test or a really good reason for its absence

Merging downstream Qemu

Merging changes from the qemu branch should be done on the emu-master-qemu branch. You will need to this on a linux machine as qemu development happens in a linux environment. Once you have obtained this branch you can add the remote qemu repository as follows:

Now you can start merging in changes:

Be smart, merge only a few commits at a time

Next you should try to build qemu standalone:

Now you are ready for building, testing, and merging the next set. You could have a look at this script to automate this slightly.

Warning: The JCenter repository became read-only on March 31st, 2021. For more information, see JCenter service update.

Android Studio Arctic Fox | 2020.3.1 has been released to the stable channel.Download it here.

Android Studio Bumblebee | 2021.1.1 is currently in the Canary and Devchannels.

Android Gradle plugin (AGP) 7.0 has been released to the stable channel.For more information, see the AGP release notes.

For the latest news on releases, including a list of notable fixes ineach release, also see the Release updates.

If you encounter any problems using a preview version of Android Studio, pleaselet us know. Your bug reports help to make AndroidStudio better.

Android Studio Bumblebee | 2021.1.1

The following are new features in Android Studio Bumblebee.

Lint analysis task is now cacheable

The AndroidLintAnalysisTask is now compatible with the Gradle buildcache.If you enable the build cache by setting org.gradle.caching=true in yourgradle.properties file, the lint analysis task will get its output from thebuild cache when possible.

The lint analysis task is often the biggest bottleneck when running lint withthe Android Gradle plugin, so enabling the build cache improves build speed whenrunning lint in many situations. You should see a noticeable performanceimprovement, for example, if you have a multi-module project and clean yourbuild directory before running lint on your CI server.

C/C++ modules may now reference other C/C++ modules in the same project

A Gradle Android module with C/C++ code may now be set up to reference headerfiles and library code in another Gradle module. ThePrefab protocol is used to communicate theheaders and libraries between Gradle modules.

Requirements

  • The consuming module must be CMake and not ndk-build. Support for ndk-build will require a future NDK update. The publishing module may be CMake orndk-build.

  • The consuming module must enable prefab in the build.gradle file.

  • The publishing module must enable prefabPublishing in the build.gradle file.
  • The consuming module must reference the publishing module by adding a line in the build.gradle file dependencies block. For example:
  • The publishing module must expose a package using a prefab section. For example:
  • The consuming module's CMakeLists.txt file may use find_package() to locate thepackage published by the producing module. For example:
  • There must be one STL for the entire application. So, for example, both consuming and publishing modules can use C++ shared STL.

For further explanation of how to configure native AAR consumers and producers with AGP, see Native dependencies with AGP.

Support for KMP test execution

Starting from Android Studio Bumblebee Canary 13, you can run tests for KotlinMultiplatform (KMP) projects from Android Studio

In order to ensure your tests run successfully from Android Studio, make sure you have all the requirements below:

  • AGP 7.0.0-alpha08 or higher
  • Gradle 6.8.2 or higher
  • Kotlin plugin 1.4.30 or higher

Repository and version settings in settings.gradle file

When a new project is created in Android Studio Bumblebee, the top-levelbuild.gradle file only contains code to clean your build directory:

The repository and Android Gradle plugin version settings that were previouslyin the top-level build.gradle file are now in the settings.gradle file:

The module-level build.gradle file has not changed. So, use thesettings.gradle file to define build configurations that apply to all modulesin your project, or the repositories and dependencies that apply to Gradleitself; use the module-level build.gradle file to define build configurationsthat are specific to a given module within your project.

New Device Manager

The Device Manager is a stand-in replacement for the AVD Manager, both fromAndroid Studio’s Welcome Screen or after you open a project. The Device Managerintroduces some new capabilities that make this feature more easy to create andmanage all of your local test devices, such as:

  • A more flexible UI that supports being docked in the IDE, floating, or in aseparate window, like you can with other Android Studio tool windows. This givesyou easier access to your devices without obstructing other windows of the IDE.
  • A Virtual tab that allows you to create, manage, and deploy virtual devices;see details of each device at a glance; or quickly inspect the device in theDevice File Explorer with a single click.
  • A Physical tab that allows you to quickly pair to a new device using ADB Wifiand see details of each physical device at a glance. You can also quicklyinspect each device’s file system using the Device File Explorer with a click ofa button.

To open the new Device Manager, do one of the following:

  • From the Android Studio Welcome screen, select More Actions > Virtual DeviceManager.
Note: You can currently create and manage only virtual devices from the welcomescreen.
  • After opening a project, select View > Tool Windows > Device Manager fromthe main menu bar.

New in Layout Inspector

Capture layout hierarchy snapshots

Layout Inspector now allows you to save snapshots of your running app’s layouthierarchy, so that you can easily share them with others or refer to them later.

Snapshots capture the data you would typically see when using the LayoutInspector, including a detailed 3D rendering of your layout, the component treeof your View, Compose, or hybrid layout, and detailed attributes for eachcomponent of your UI. To save a snapshot, do the following:

  1. Deploy your app to a device running API level 23 or higher
  2. Open the Layout Inspector by selecting View > Tool Windows > LayoutInspector.
  3. The Layout Inspector should connect to your app process automatically. Ifnot, select the app process from the dropdown menu.
  4. When you want to capture a snapshot, click Export snapshot from the Layout Inspectortoolbar.
  5. In the system dialog that appears, specify the name and location you want tosave your snapshot. Make sure to save the file with a *.li extension.

You can then load a Layout Inspector snapshot by selecting File > Open fromthe main menu bar, and opening a *.li file.

Support for inspecting Compose semantics

In Compose, Semanticsdescribe your UI in an alternative manner that is understandable forAccessibilityservices and for theTesting framework. InAndroid Studio Bumblebee, you can now use the Layout Inspector to inspectsemantic information in your Compose layouts.

When selecting a Compose node, use the Attributes window to check whether itdeclares semantic information directly, merges semantics from its children, orboth. To quickly identify which nodes include semantics, either declared ormerged, use select the View options dropdown in the Component Treewindow and select Highlight Semantics Layers. This highlights only the nodesin the tree that include semantics, and you can use your keyboard to quicklynavigate between them.

Android Emulator Apple Silicon Preview Software

Avoid Activity restarts

Connecting the Layout Inspector to a running app on older versions of AndroidStudio would cause your app’s Activity to restart. This is required to set adevice flag that enables inspection of your app’s layouts.

In Android Studio Bumblebee, you can avoid Activity restarts when connecting theLayout Inspector by setting this flag ahead of time using one of the followingsteps:

  • Enable a Run Configuration option

    1. Select Run > Edit Configurations from the main menu bar. TheRun/Debug Configurations dialog appears.
    2. Navigate to the run configuration you would like to use.
    3. In the Layout Inspector options section, check the box next toConnect to Layout Inspector without restarting activity.
    4. Use the run configuration the next time you want to inspect your appusing the Layout Inspector.
  • Set the flag from the command line:

    1. Open a terminal window on the machine that’s connected to your device
    2. Set the device flag for your app using the following command:
    1. Deploy your app to the device and connect the Layout Inspector. AndroidStudio will check whether the flag is set and avoid restarting the Activityif possible.
Note: While typically not noticeable, setting this device flag when not usingthe Layout Inspector might affect the app’s performance.

New in App Inspection

In Android Studio Bumblebee, there are new tools and functionalities in the AppInspection window. You can open the App Inspector by selecting View > ToolWindows > App Inspection from the main menu bar.

Network Inspector

The Network Profiler in the Profilers tool window has now moved to the AppInspection tool window. If you’ve previously used the Network Profiler, allthe same features and rich network traffic data is still available. Simplydeploy your app to a device running API level 26 and higher and open the AppInspector > Network Inspector tab.

Inspect Jobs, Alarms, and Wakelocks

Android Emulator Apple Silicon Preview App

The Background Task Inspector now allows you to inspect your app’s Jobs,Alarms, and Wakelocks, in addition to the existing support for inspectingWorkers. Each type of asynchronous task now appears under the appropriateheading in the inspector tab, allowing you to easily monitor its status andprogress. Similar to Workers, you can select a Job, Alarm, or Wakelock toinspect its detailed information in the Task Details panel.

Note: This functionality has been migrated from the Energyprofiler. So youshould now use the Background task inspector to inspect all of your app’sasynchronous tasks.

Because Workers use Jobs and Wakelocks under the hood, those tasks that arescheduled by Workers appear as children of each Worker. Keep in mind, you canonly see Workers in the Graph mode.

Android Testing

Android Studio Bumblebee Canary 8 and AGP 7.1.0 alpha-08 introduce several newfeatures and improvements tohelp you more reliably and scalably run your automated instrumentation tests andsee useful results you can use to debug issues. These are features in additionto those launched in Android Studio Arctic Fox, such as parallel devicetesting and Gradle test runner for unittests.

Unified Gradle test runner

When running instrumented tests, previous versions of Android Studio used theIntelliJ Android instrumented test runner. Meanwhile, the Android Gradle pluginuses Gradle’s own implementation of the Android instrumented test runner. So,depending on whether you run your tests from Android Studio or from the commandline using the Gradle plugin, such as on your continuous integration server, youmight see different test results, such as tests passing using one runner andfailing on another.

To resolve this issue, Android Studio Bumblebee now also uses Gradle’s Androidinstrumented test runner when running your tests. Now, when running yourautomated instrumentation tests from Android Studio, your results are morelikely to be consistent with those you run using the Android Gradle plugin fromthe command line.

If you already have instrumented test configurations saved to your project,they’ll now use Gradle to run tests on your connected device. Otherwise, you cancreate a new instrumented test configuration using the gutter action next toyour test class or method, as shown below.

When running your instrumented tests, you can confirm that Android Studio isusing the Gradle test runner by inspecting the test output in the Test Matrixfor Gradle task output. Although we are improving this feature with each releaseof Android Studio, there are some known issues. If you are experiencing issues, please report abug.You can also disable the new testing pipeline to revert to theold behavior.

Gradle Managed Virtual Devices

In order to improve consistency, performance, and reliability when using AndroidVirtual Devices for your automated instrumented tests, we’re introducing GradleManaged Virtual Devices. This feature allows you to configure virtual testdevices in your project's Gradle files that the build system uses to fullymanage—that is, create, deploy, and tear down—those devices to execute yourautomated tests.

Because this feature grants Gradle visibility into not only the tests you’rerunning, but also the devices’ lifecycle, it’s able to improve the quality ofyour testing experience in the following ways:

  • Handles device-related issues in order to ensure your tests are executed
  • Utilizes emulator snapshots to improve device startup time and memory usage, and restore devices to a clean state between tests
  • Caches test results and reruns only tests that are likely to provide different results
  • Provides a consistent environment for running your tests between local and remote test runs
Get started

You can specify a virtual device that you want Gradle to use for testing yourapp in your module-level build.gradle file. The following code sample creates aPixel 2 running API level 29 as a Gradle managed device.

To run your tests using the Gradle managed devices you configured, use thefollowing command. device-name is the name of the device you configured inyour Gradle build script (such as pixel2api29), and BuildVariant is thebuild variant of your app you want to test.

Define groups of devices

To help you scale your tests across multiple device configurations, such asdifferent API levels and form factors, you can define multiple Gradle manageddevices and add them to a named group. Gradle can then execute your tests acrossall the devices in the group in parallel.

The example below shows two managed devices added to a device group calledphoneAndTablet.

To run your tests using the group of Gradle managed devices, use the followingcommand.

Android Emulator now runs directly inside Android Studio by default

Launching the emulator inside Studio conserves screen real estate,and gives you the ability to write and test your apps inside one windowwithout leaving Android Studio.

When the emulator is running, you'll have access to common emulator actions like rotating,and extended control options like navigation playback. To run the emulator in a separatewindow instead go to File > Settings > Tools > Emulator and deselect Launch in a tool window.

Compatibility with Emulator Snapshots for test failures

Test runs using Gradle managed devices are compatible with Emulator snapshotsfor test failures.That is, when you enable snapshots for test failures when runningtests with managed devices, Gradle will also generate a snapshot for each testassertion failure, so that you can use them to debug the issue later. To usemanaged virtual devices with Emulator snapshots for test failures enabled,simply include the command-line flag to enable snapshots.

Keep in mind, to use the snapshots, you’ll need toimport the test results into Android Studio.

Android Emulator Online

Emulator Snapshots for test failures

When you inspect failed assertions after running instrumented tests, it'ssometimes difficult or time consuming to reproduce that test failure again.However, reproducing those failures on your connected device is critical inhelping you diagnose the issue, either by attaching a debugger or interactingwith the app at the time of failure.

When using Android Studio Bumblebee with In Android Gradle plugin 7.0-alpha13and higher, you can use Emulator Snapshots for test failures – a quicker way toreproduce test failures when using the Android Emulator. In other words, whenyour instrumented tests running on a connected Emulator encounter a Java orKotlin assertion that fails, the device takes a snapshot at the time of failure.After your test run completes, you can then reload the snapshot on the samedevice in order to reproduce and investigate that failure.

To get started, first update the Android Emulatorto 30.4.3 or higher, then follow these steps:

Emulator
  1. Select Run > Edit Configurations … from the menu bar.
  2. If you don’t already have an instrumented test configuration,create an instrumented test configurationyou want to run.
  3. Open the instrumented test configuration and select Yes from the dropdownnext to Enable Emulator Snapshots for test failures.
  4. By default, Android Studio generates up to two snapshots per device, per testrun. To change this maximum number of snapshots, enter the desired amountnext to Max Snapshots per test run.
  5. If you want to compress snapshots,check the box next to Compress snapshots.
  6. Click OK.
  7. Deploy your tests to a virtual device as you normally would.

The Run window should appear and show you the results of your test run. Toload a snapshot, select a failed test that indicates Test results in thecolumn under the device name. In the right side of the tool window, select theRetention tab. After Android Studio validates the snapshot for that testfailure, click the Start retention debug button to load the snapshot to adevice. You can then attach a debugger to investigate the cause of the issue.

Enable snapshots for command-line tests

You can enable emulator snapshots for tests you run from the command line in oneof two ways: by enabling it in your app module’s build.gradle file or bypassing parameters to the Gradle connectedCheck task. To enable the feature inyour Gradle buildscript, include the following in your app module’sbuild.gradle file.

Note: Due to the large number of write operations during snapshotgeneration, for better performance we recommend using this feature on systemswith an SSD instead of an HDD.

Next, start the Android Virtual Device you'd like to use and run your app'sinstrumented tests from the command line, as follows:

Linux and Mac

./gradlew connectedCheck

Windows

gradlew connectedCheck

Alternatively, if you don’t want to enable the feature in your app'sbuild.gradle file, you can simply pass the following properties in thecommand line:

Import test failures into Android Studio

If you’re running your tests from outside of Android Studio, you need to importyour test results into the IDE in order to use any of the generatedsnapshots.After the tests complete, you should see test results in the<project>/<module>/build/outputs/androidTest-results/connected/ folder. If your test run encountered anassertion failure, you should see a tar snapshot file for each snapshot thatwas taken. To see the results in Android Studio and load the snapshots to yourrunning virtual device, select Run >Import Tests from File from the menu bar, navigate to the test-result.pbfile from the test results directory, and click Open.

The Run window should appear and show you the results of your test run.

Note: Snapshots must be used on the same workstation and with the samedevice used to generate the snapshot during the test run. Additionally,the device must be started with the same parameters. So, if you started thedevice with Android Studio or the command line, it's recommended you start thedevice using the same method before loading a snapshot.

Compress snapshots

Snapshots provide high fidelity in reproducing your test failures, but theyeach consume a large amount of disk space. If you want to instead generatecompressed snapshots, add the following to your build.gradle file. Keep inmind, compressing snapshots increases the time it takes to complete theprocess and continue with the test execution.

Alternatively, you can pass the following property from the command line.

Disable the new testing pipeline

By default Android Studio Bumblebee uses Gradle to run its instrumentation tests.If you're experiencing issues, you can disable this behavior as follows:

  1. Select File > Settings > Build, Execution, Deployment > Testing(or Android Studio > Preferences > Build, Execution, Deployment > Testingon MacOS.)
  2. Uncheck the box next to Run Android instrumented tests using Gradle andclick OK.

If you're using AGP 7.1.0-alpha08 and higher, you can also revert to olderbehaviors by doing one of the following:

  • When running Gradle tasks from the command line, use the following commandline parameter:-Pandroid.experimental.androidTest.useUnifiedTestPlatform=false
  • Add the following parameter to your project's gradle.properties file:android.experimental.androidTest.useUnifiedTestPlatform=false

To help resolve issues that you might be expereincing, please report abug.

Improved resource shrinker

Android Studio Bumblebee includes an improved resource shrinker that helpsreduce your app size.

Support for apps with dynamic features

The default implementation of the Android resource shrinker has been updated inAndroid Gradle Plugin 7.1.0-alpha09. The new implementation supports shrinkingapps with dynamic features.

Experimental further app size reductions

The new resource shrinker implementation can reduce the size of your shrunk appeven more by modifying the resource table to remove unused value resources andreferences to unused file resources. The new resource shinker can delete unusedfile resources completely, reducing the size of your app more. This behavior isnot enabled by default yet, but you can opt in to try it by adding theexperimental optionandroid.experimental.enableNewResourceShrinker.preciseShrinking=trueto your project's gradle.properties file.

Please report any issues you find with the new resource shrinker or theexperimental flag. To help diagnose issues, or as a temporary workaround, youcan switch back to the previous implementation by addingandroid.enableNewResourceShrinker=false to your project's gradle.properties.The new shrinker replaces unused file-based resources with slightly differentminimal files than the previous resource shrinker, but this is not expected tohave any runtime impact.

The old implementation is scheduled to be removed in Android Gradle plugin 8.0.0.

Build variant publishing

Android Gradle plugin 7.1.0 and higher allows you to configure which buildvariants to publish to an Apache Maven repository. AGP creates a componentwith a single or multiple build variants based on the new publishing DSL, whichyou can use to customize a publication to a Maven repository. Compared toprevious versions, this also avoids unnecessary work, as no components will becreated by default. To learn more, see the publishing code sample.

Publish Javadoc JAR

AGP 7.1.0 and higher allows you to generate Javadoc from Javaand Kotlin sources and publish Javadoc JAR files in addition to AARs for libraryprojects. The Javadoc will be added to the POM andGradle Module Metadata files. Enable this feature by adding withJavadocJar() under thesingleVariant or multipleVariants publishing block. To learn more, see thepublishing options code sample.