New features in Android Studio Preview

Android Studio 3.1.3 has been released to the stable channel. Download it here.

The latest Canary channel preview version is Android Studio 3.3 Canary 3.

The latest Beta channel preview version is Android Studio 3.2 Beta 4. This page provides a summary of the new features and changes in this preview version.

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

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

What's New Assistant

Android Studio 3.2 has a new Assistant panel, which informs you about the latest changes in Android Studio.

The panel opens when you start Android Studio if it detects that there is new information to show. You can also open the Assistant panel by choosing Help > What's new in Android Studio.

Android Jetpack

Android Jetpack helps to accelerate Android development with components, tools, and guidance that eliminate repetitive tasks and enable you to more quickly and easily build high-quality, testable apps. Android Studio includes the following updates to support Jetpack. For more information, see the Jetpack documentation.

The new Navigation Editor integrates with the navigation components of Android Jetpack to provides a graphical view for creating the navigation structure of your app. The Navigation Editor simplifies the design and implementation of navigation between in-app destinations.

In Android Studio 3.2, the Navigation Editor is an experimental feature. To enable the Navigation Editor, click File > Settings (Android Studio > Preferences on Mac), select the Experimental category in the left pane, and check the box next to Enable Navigation Editor.

To learn more, read the Navigation Editor documentation.

AndroidX migration

As part of Jetpack, we are migrating the Android Support Libraries to a new Android extension library using the androidx namespace. For more information, read the AndroidX announcement.

Android Studio 3.2 helps you through this process with a new migration feature.

To migrate an existing project to AndroidX, choose Refactor > Migrate to AndroidX. If you have any maven dependencies that have not migrated to the AndroidX namespace, the Android Studio build system will also automatically convert those project dependencies.

The Android Gradle plugin provides the following global flags that you can set in your gradle.properties file:

  • android.useAndroidX: When set to true, this flag indicates that you want to start using AndroidX from now on. If the flag is absent, Android Studio behaves as if the flag were set to false.
  • android.enableJetifier: When set to true, this flag indicates that you want to have tool support (from the Android Gradle plugin) to automatically convert existing third-party libraries as if they were written for AndroidX. If the flag is absent, Android Studio behaves as if the flag were set to false.

Set both flags to false if you do not yet want to migrate. (This is equivalent to not having the flags in the gradle.properties file.)

Both flags are set to true when you use the Migrate to AndroidX command or create a new project with minSdkVersion set to "P".

Important: In the current Android Studio 3.2 Canary version, there is a known issue that causes the android.useAndroidX flag to not be set when you use the Create New Project wizard. For now, you need to set the flag manually in your gradle.properties file.

If you want to start using AndroidX libraries immediately and don't need to convert existing third-party libraries, you can set the android.useAndroidX flag to true and the android.enableJetifier flag to false.

Android App Bundle

Android App Bundle is a new upload format that includes all of your app’s compiled code and resources, but defers APK generation and signing to the Google Play Store.

Google Play’s new app serving model, called Dynamic Delivery, then uses your app bundle to generate and serve optimized APKs for each user’s device configuration, so each user downloads only the code and resources they need to run your app. You no longer need to build, sign, and manage multiple APKs, and users get smaller, more optimized downloads.

Additionally, you can add dynamic feature modules to your app project and include them in your app bundle. Through Dynamic Delivery, your users can then download and install your app’s dynamic features on demand.

To build a bundle, choose Build > Build Bundle(s) / APK(s) > Build Bundle(s).

For more information, including instructions for building and analyzing an Android App Bundle, see Getting started with the Android App Bundle.

Sample data in Layout Editor

Many Android layouts have runtime data that can make it difficult to visualize the look and feel of a layout during the design stage of app development. You can now easily see a preview of your view in the Layout Editor filled with sample data. When you add a view, a button appears below the view in the Design window. Click this button to set the design-time view attributes. You can choose from a variety of sample data templates and specify the number of sample items with which to populate the view.

To try using sample data, add a RecyclerView to a new layout, click the design-time attributes button below the view, and choose a selection from the carousel of sample data templates.

Slices

Slices provide a new way to embed portions of your app's functionality in other user interface surfaces on Android. For example, slices make it possible to show app functionality and content in Google Search suggestions.

Android Studio 3.2 has a built-in template to help you to extend your app with the new Slice Provider APIs, as well as new lint checks to ensure that you're following best practices when constructing the slices.

To get started right-click a project folder and choose New > Other > Slice Provider.

To learn more, including how to test your slice interactions, read the Slices getting started guide.

IntelliJ IDEA 2018.1.1

The core Android Studio IDE has been updated with improvements from IntelliJ IDEA through the 2018.1.1 release.

Android profilers

Try the following new Android Profiler features on the latest version of Android Studio 3.2.

Energy Profiler

The Energy Profiler displays a visualization of the estimated energy usage of your app.

The Energy Profiler appears as a new row at the bottom of the Profiler window when you run your app on a connected device or Android Emulator running Android 8.0 (API 26) or higher.

Click the Energy row to maximize the Energy Profiler view. Place your mouse pointer over a bar in the timeline to see a breakdown of energy use by CPU, network, and location (GPS) resources, as well as system events such as wakelocks, alarms, and jobs.

Sessions

You can now save Profiler data as "sessions" to revisit and inspect later. (The profiler keeps your session data until you restart the IDE.)

After you deploy your app by selecting Run > Profile from the main menu, start a new session by clicking and selecting an app process from the dropdown menu, as shown below.

When you record a method trace or capture a heap dump, the IDE adds that data (along with your app's network activity) as a separate entry to the current session, and you can easily switch back and forth between recordings to compare data. To stop adding data to the current session, click .

System Trace

In the CPU profiler, select the new System Trace configuration to inspect your device's system CPU and thread activity. This trace configuration is built on systrace and is useful for investigating system-level issues, such as UI jank.

While using this new trace configuration, you can visually mark important code routines in the profiler timeline by instrumenting your code with the Trace class.

Inspect JNI references in the Memory Profiler

If you deploy your app to a device running Android 8.0 (API level 26) or higher, you can now inspect memory allocations for your app’s JNI code using the Memory Profiler.

While your app is running, select a portion of the timeline that you want to inspect and select JNI heap from the drop-down menu above the class list, as shown below. You can then inspect objects in the heap as you normally would and double-click objects in the Allocation Call Stack tab to see where the JNI references are allocated and released in your code.

Import and inspect memory heap dump files

You can now import and inspect .hprof memory heap dump files created with the Memory Profiler.

Import your .hprof file by clicking Start new profiler session in the profiler’s Sessions pane and then selecting Load from file. You can then inspect its data in the Memory Profiler as you would any other heap dump.

Record CPU activity during app startup

You can now record CPU activity during your app's startup as follows:

  1. Select Run > Edit Configurations from the main menu.
  2. Under the Profiling tab of your desired run configuration, check the box next to Start recording a method trace on startup.
  3. Select a CPU recording configuration to use from the dropdown menu.
  4. Deploy your app to a device running Android 8.0 (API level 26) or higher by selecting Run > Profile.

Export CPU traces

After you record CPU activity with the CPU profiler, you can export the data as a .trace file to share with others or inspect later.

To export a trace after you’ve recorded CPU activity, do the following:

  1. Right-click on the recording you want to export from the CPU timeline.
  2. Select Export trace from the dropdown menu.
  3. Navigate to where you want to save the file and click Save.

Import and inspect CPU trace files

You can now import and inspect .trace files created with the Debug API or CPU profiler. (Currently, you can't import System Trace recordings.)

Import your trace file by clicking Start new profiler session in the profiler’s Sessions pane and then selecting Load from file. You can then inspect its data in the CPU profiler similar to how you normally would, but there are a few exceptions:

  • CPU activity is not represented along the CPU timeline.
  • The thread activity timeline indicates only where trace data is available for each thread and not actual thread states (such as running, waiting, or sleeping).

Record CPU activity using the Debug API

You can now start and stop recording CPU activity in the CPU profiler by instrumenting your app with the Debug API. After you deploy your app to a device, the profiler automatically starts recording CPU activity when your app calls startMethodTracing(String tracePath), and the profiler stops recording when your app calls stopMethodTracing(). While recording CPU activity that’s triggered using this API, the CPU profiler shows Debug API as the selected CPU recording configuration.

Lint checking

Android Studio 3.2 includes many new and improved features for lint checking.

Lint checks for Java/Kotlin interoperability

To make sure your Java code interoperates well with your Kotlin code, new lint checks enforce the best practices described in the Kotlin Interop Guide. These checks includes looking for the presence of Nullability annotations, use of Kotlin hard keywords, placing lambda parameters last, and others.

To enable these checks, go to File > Preferences > Editor > Inspections and check the rules that you want to enable under Kotlin Interoperability, as shown below. You can then run the checks by selecting Analyze > Inspect Code from the main menu.

To enable these checks for command-line builds, add the following to your build.gradle file:

android {
    lintOptions {
        check 'Interoperability'
    }
}

Lint checks for slices

New lint checks for slices help to ensure that you are constructing slices correctly. For example, lint checks warn you if you have not assigned a primary action to a slice.

More new lint checks

Beyond the lint checks for slices and Kotlin interoperability described in the previous sections, Android Studio 3.2 implements 20 new lint checks to help you to find and identify common code problems. These new checks range from warnings about potential usability issues to high-priority errors regarding potential security vulnerabilities.

New Gradle target

Use the new lintFix Gradle task to apply all of the safe fixes suggested by the lint check directly to the source code. An example of a lint check that suggests a safe fix to apply is SyntheticAccessor.

Metadata updates

Various metadata, such as the service cast check, have been updated for lint checks to work with Android P Developer Preview.

Warning if running lint on a new variant

Lint now records which variant and version a baseline is recorded with, and lint warns you if you run it on a different variant than the one with which the baseline was created.

Improvements to existing lint checks

Android Studio 3.2 includes many improvements to existing lint checks. For example, the resource cycle checks now apply to additional resource types, and the translation detector can now find missing translations on the fly, in the editor.

Issue IDs more discoverable

Issue IDs are now shown in more places now, including in the Inspection Results window, making it easier for you to find the information that you need to enable or disable specific checks through lintOptions in build.gradle.

For more information, see Configure lint options with Gradle.

Data Binding V2

Data Binding V2 is now enabled by default and is compatible with V1. This means that, if you have library dependencies that you compiled with V1, you can use them with projects using Data Binding V2. However, note that projects using V1 cannot consume dependencies that were compiled with V2.

D8 desugaring

In Android Studio 3.1, we integrated desugaring step into the D8 tool as an experimental feature, reducing overall build time. Now, in Android Studio 3.2, desugaring with D8 is turned on by default.

New code shrinker

R8 is a new tool for code shrinking and obfuscation that replaces ProGuard. You can start using the preview version of R8 by including the following in your project’s gradle.properties file:

android.enableR8 = true

Changed default ABIs for multi-APKs

When building multiple APKs that each target a different ABI, the plugin no longer generates APKs for the following ABIs by default: mips, mips64, and armeabi.

If you want to build APKs that target these ABIs, you must use NDK r16b or lower and specify the ABIs in your build.gradle file, as shown below:

splits {
    abi {
        include 'armeabi', 'mips', 'mips64'
        ...
    }
}

Improved editor features for CMake build files

If you use CMake to add C and C++ code to your project, Android Studio now includes improved editor features while you edit your CMake build scripts, such as:

  • Syntax highlighting and code-completion: The IDE now highlights and suggests code completion for common CMake commands. Additionally, you can navigate to a file by clicking it while pressing the Control key (or Command on MacOS).
  • Code reformatting: You can now use IntelliJ’s code reformat option to apply code styles to your CMake build scripts.
  • Safe refactoring: The IDE’s built-in refactoring tools now also check if you are renaming or deleting files that you reference in your CMake build scripts.

When using the Project window in previous versions of Android Studio, you could navigate and inspect only the header files that belong to libraries you build from a local project. With this release, you can now also view and inspect header files included with external C/C++ library dependencies that you import into your app project.

If you already include C/C++ code and libraries in your project, open the Project window on the left side of the IDE by selecting View > Tool Windows > Project from the main menu and select Android from the drop-down menu. In the cpp directory, all headers that are within the scope of your app project are organized under the include node for each of your local C/C++ library dependencies, as shown below.

Native multidex enabled by default

Previous versions of Android Studio enabled native multidex when deploying the debug version of an app to a device running Android API level 21 or higher. Now, whether you’re deploying to a device or building an APK for release, the Android plugin for Gradle enables native multidex for all modules that set minSdkVersion=21 or higher.

AAPT2 moved to Google's Maven repository

Beginning with Android Studio 3.2 Canary 11, the source for AAPT2 (Android Asset Packaging Tool 2) is Google's Maven repository.

To use AAPT2, make sure that you have a google() dependency in your build.gradle file, as shown here:

  buildscript {
      repositories {
          google() // here
          jcenter()
      }
      dependencies {
          classpath 'com.android.tools.build:gradle:3.2.0-alpha12'
      }
  } allprojects {
      repositories {
          google() // and here
          jcenter()
  }

The new version of AAPT2 fixes many issues, including improved handling of non-ASCII characters on Windows.

Removal of configuration on demand

The Configure on demand preference has been removed from Android Studio.

Android Studio no longer passes the --configure-on-demand argument to Gradle.

ADB Connection Assistant

The new ADB Connection Assistant provides step-by-step instructions to help you set up and use a device over the Android Debug Bridge (ADB) connection.

To start the assistant, choose Tools > Connection Assistant.

The ADB Connection Assistant provides instructions, in-context controls, and a list of connected devices in a series of pages in the Assistant panel.

Emulator improvements

You can now save and load snapshots of an AVD (Android virtual device) at any time in the Android Emulator, making it fast and easy to return an emulated device to a known state for testing. When you edit an AVD using the AVD Manager, you can specify which AVD snapshot to load when the AVD starts.

Controls for saving, loading, and managing AVD snapshots are now in the Snapshots tab in the emulator's Extended controls window.

See the Android Emulator 27.3.0 Canary release notes for details.