New features in Android Studio Preview

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

Android Studio 4.1 is currently in the Canary and Dev channels.

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.

Android Studio 4.1

This section provides a summary of the new features and changes in Android Studio 4.1.

Material Design Components: Updated themes and styles in new project templates

Animation: Creating a project in Android Studio with new material design properties.

Android Studio templates in the Create New Project dialog now use Material Design Components (MDC) and conform to updated guidance for themes and styles by default. Updates include:

  • MDC: Projects depend on com.google.android.material:material in build.gradle. Base app themes use Theme.MaterialComponents.* parents and override updated MDC color and “on” attributes.
  • Color resources: Color resources in colors.xml use literal names (for example, purple_500 instead of colorPrimary).
  • Theme resources: Theme resources are in themes.xml (instead of styles.xml) and use Theme.<ApplicationName> names.
  • Dark theme: Base application themes use DayNight parents and are split between res/values and res/values-night.
  • Theme attributes: Color resources are referenced as theme attributes (for example, ?attr/colorPrimary) in layouts and styles to avoid hard-coded colors.

IDE configuration directory changes in Canary 9

In the Canary 9 release, the locations for user configuration directories have been changed to the following:

Windows

Syntax: %APPDATA%\Google\<product><version>

Example: C:\Users\YourUserName\AppData\Roaming\Google\AndroidStudioPreview4.1

macOS

Syntax: ~/Library/Application Support/Google/<product><version>

Example: ~/Library/Application Support/Google/AndroidStudioPreview4.1

Linux

Syntax: ~/.config/Google/<product><version>

Example: ~/.config/Google/AndroidStudioPreview4.1

These new directory locations are consistent with recent updates to IntelliJ IDEA, the IDE on which Android Studio is based.

Improved instrumentation testing

Starting in Android Studio 4.1 Canary 8, instrumentation tests can now be run across multiple devices in parallel and investigated using a specialized instrumentation test results panel. Using this panel, you can determine if tests are failing due to API level or hardware properties.

Insrumentation test panel

Testing your app across a wide variety of API levels and form factors is one of the best ways to ensure that all users have a great experience when using your app.

To take advantage of this feature:

  1. Select Modify Device Set in the target device dropdown menu (in the top-center of the IDE).

    Target device dropdown

  2. Select the target devices and click OK.

    Modify device set dialog

  3. Select Multiple Devices in the target device dropdown menu and run your tests.

    Select Multiple Devices from target device dropdown

To view your test results in the Run panel, go to View > Tool Windows > Run.

The new test results panel allows you to filter your test results by status, device, and API level. Additionally, you can sort each column by clicking the header. By clicking on an individual test, you can view logs and device information individually for each device.

Dagger navigation support

IDE gutter actions for navigating to Dagger consumers and providers

Android Studio makes it easier to navigate between your Dagger-related code by providing new gutter actions and extending support in the Find Usages window.

  • New gutter actions: For projects that use Dagger, the IDE provides gutter actions that help you navigate between your Dagger-annotated code. For example, clicking on the gutter action next to a method that consumes a given type navigates you to the provider of that type. Conversely, clicking on the gutter action navigates you to where a type is used as a dependency.

  • Find Usages node: When you invoke Find Usages on a provider of a given type, the Find window now includes a Dependency consumer(s) node that lists consumers of that type. Conversely, invoking this action on a consumer of a Dagger-injected dependency, the Find window shows you the provider of that dependency.

Run the Android Emulator directly in Android Studio

You can now run the Android Emulator directly in Android Studio. Use this feature to conserve screen real estate, to navigate quickly between the emulator and the editor window using hotkeys, and to organize your IDE and emulator workflow in a single application window.

The emulator launching in a tool window in Android Studio.

To run the emulator in Android Studio, make sure you're using Android Studio 4.1 with version 30.0.10 or higher of the Android Emulator, then follow these steps:

  1. Click File > Settings > Tools > Emulator (or Android Studio > Preferences > Tools > Emulator on macOS), then select Launch in a tool window and click OK.
  2. If the Emulator window didn't automatically appear, open it by clicking View > Tool Windows > Emulator.
  3. Start your virtual device using the AVD Manager or by targeting it when running your app.

Limitations

Currently, you can't use the emulator's extended controls when it's running in a tool window. If your development workflow depends heavily on the extended controls, continue to use the Android Emulator as a standalone application. In addition, certain virtual devices—such as Android TV and foldable devices—can't be run in Android Studio because they have specialized UI requirements or important functions in the extended controls.

Database Inspector

With Android Studio 4.1 Canary 6 and higher, you can inspect, query, and modify your app’s databases using the new Database Inspector. For example, you can debug your running app by modifying values in your database and testing those changes on the device.

Modify table values and see the changes in your running app

To get started, deploy your app to a device running API level 26 or higher and select View > Tool Windows > Database Inspector from the menu bar.

If the Database Inspector window doesn’t automatically select your app’s process, select it from the dropdown menu.

Inspect and modify tables

In the Databases panel, you can see the database(s) for your app, and you can expand a database node to see its tables. When you double-click on a table, the inspector opens it in a separate tab on the right, as shown in the screenshot below, where you can inspect its data, sort by columns, or even modify values as your app is running on the device.

To change the value of a table cell, simply double-click into the cell, change its value, and press Enter. If you're using the Room persistence library and observing your databases (such as with LiveData), those changes should be visible in your running app almost immediately. Otherwise, you might need to refresh your app's query of the database to see your changes.

Inspect, query, and modify your app’s databases

If your app makes updates to its database and you want to automatically see those updates in the inspector window, check the box next to Live updates. Keep in mind, while this option is enabled, the table in the inspector becomes read-only and you can not modify its values.

Alternatively, you can manually update the data in the inpector by clicking Refresh Table. Similarly, if there are changes to database schemas, click Refresh Schema in the Databases panel.

Query your database

To query a database, click Open New Query tab in the Databases panel. This opens a New Query tab on the right. If your app includes more than one database, select the database you want to query using the dropdown menu in the tab window. In the text field, you can specify your SQLite query and click Run. The inspector queries your app’s database and returns the result, as shown below.

Query your database

If you use the Room persistence library, Android Studio also provides gutter actions to help you quickly run queries you define in your @Query annotations. While your app is deployed to a compatible device and the Database Inspector is open in the IDE, click the button next to a @Query annotation, as shown below.

Room Query annotation gutter action

The Database Inspector opens a new tab, runs the query, and returns the results. If your query includes named bind parameters, such as :name, Android Studio requests values for each parameter before running the query.

Prevent new and existing databases from closing

If your app frequently connects to and disconnects from databases, it can be difficult to inspect those databases. That's because inspecting, querying, and modifying a database requires that your app maintain a live connection to it. The Database Inspector window uses icons to help you identify open () and closed () databases.

To make it easier to inspect those databases, you can prevent new and existing connections to your databases from closing by clicking Keep database connections open . When this behavior is enabled, the Keep database connections open button changes to .

Native Memory Profiler

The Android Studio Memory Profiler now includes a Native Memory Profiler for apps deployed to physical devices running Android 10 or later. With a sample size of 32 bytes, the Native Memory Profiler tracks allocations/deallocations of objects in native code for a specific time period and provides the following information:

  • Allocations: A count of objects allocated via malloc() or the new operator during the selected time period.
  • Deallocations: A count of objects deallocated via free() or the delete operator during the selected time period.
  • Allocations Size: The aggregated size in bytes of all allocations during the selected time period.
  • Deallocations Size: The aggregated size in bytes of all freed memory during the selected time period.
  • Total Count: The value in the Allocations column minus the value in the Deallocations column.
  • Remaining Size: The value in the Allocations Size column minus the value in the Deallocations Size column.

Native Memory Profiler

To initiate a recording, click Record native allocations at the top of the Memory Profiler window:

Record native allocations button

When you're ready to complete the recording, click Stop recording.

Use TensorFlow Lite models

ML Model Binding makes it easy for you to directly import .tflite model files and use them in your projects. Android Studio generates easy-to-use classes so you can run your model with less code and better type safety.

Supported models

The current Canary implementation of ML Model Binding supports image classification and style transfer models, provided they are enhanced with metadata. Over time, support will be expanded to other problem domains, like object detection, image segmentation, and text classification.

A wide range of pre-trained image classification models are provided on TensorFlow Hub – just look for and download the model formats that mention "metadata". You can also add metadata to a TensorFlow Lite model yourself, as is outlined in Adding metadata to TensorFlow Lite model.

Import a model file

To import a supported model file, follow these steps:

  1. Open the TensorFlow Lite model import dialog in the File menu at File > New > Other > TensorFlow Lite Model.
  2. Select the .tflite model file that you previously downloaded or created.
  3. Click Finish.

This imports the model file into your project and places it in the ml/ folder; if the directory doesn't exist, Android Studio will create it for you.

Import a TensorFlow Lite model

View model metadata and usage

To see the details for an imported model and get instructions on how to use it in your app, double-click the model file in your project to open the model viewer page, which shows the following:

  • Model: High-level description of the model
  • Tensors: Description of input and output tensors
  • Sample code: Example of how to interface with the model in your app

Here is an example using mobilenet_v1_0.25_160_quantized.tflite:

Screenshot of TensorFlow Lite model viewer

As the example demonstrates, Android Studio creates a class called MobilenetV1025160Quantized for interacting with the model.

If the model does not have metadata, this screen will only provide minimal information.

Known issues and workarounds

  • Support for TensorFlow Lite models for problem domains other than image classification and style transfer is currently limited. Although import should work fine, some model inputs and/or outputs are represented by TensorBuffers rather than friendly types. For models without any metadata, all model inputs and outputs will be TensorBuffers.
  • Models with Input and Output data types different from DataType.UINT8 or DataType.FLOAT32 are not supported.

This feature is still under development, so please provide feedback or report bugs.

Support for Jetpack Compose

Jetpack Compose toolkit provides a modern approach to building your app's UI. The toolkit also brings all of Kotlin's benefits, such as helping you to write concise and idiomatic code that's fully interoperable with Java.

For the best experience developing with Jetpack Compose, you should use the latest version of Android Studio 4.1. That's because when you use Android Studio to develop your app with Jetpack Compose, you can benefit from smart editor features, such as New Project templates and the ability to immediately preview your Compose UI.

To learn more and get started, go to the Jetpack Compose overview.

Assertions in debug builds

Assertions in your Java code are now enabled when deploying the debug version of your app. Because the Android runtime doesn't support enabling assertions at runtime (that is, passing the equivalent of the -ea/-enableassertions flag to a Java VM), assertions in your app previously had no effect.

Now, when you build and deploy the debug version of your app using Android Gradle plugin 4.1.0-alpha01 and higher, the built-in compiler (D8) rewrites the code to enable assertions at compile time, so you always have the assertion checks active.

Apply Changes

To help you be more productive as you iterate on your app, we’ve made the following enhancements to Apply Changes for devices running Android 11 Developer Preview 3 or higher:

Faster deploy speeds

We’ve invested heavily in optimizing your iteration speed by developing a method to deploy and persist changes on a device without installing the application. After an initial deploy, subsequent deploys to Android 11 devices using either Apply Code Changes or Apply Changes and Restart Activity are now significantly faster.

To learn more about the difference between these two actions, see Apply Changes.

Support for additional code changes

For devices running Android 11 Developer Preview 3 or higher, you can now add methods and static final primitive fields and then deploy those changes to your running app by clicking either Apply Code Changes or Apply Changes and Restart Activity .

You can now also add resources and then deploy those changes to your running app on Android 11 devices by clicking Apply Changes and Restart Activity .

Export C/C++ dependencies from AARs

Android Gradle Plugin 4.0 added the ability to import [Prefab] packages in AAR dependencies as described below. Beginning with canary 10, version 4.1 enables exporting libraries from your external native build in an AAR for an Android Library project.

To export your native libraries, add the following to the android block of your library project's build.gradle file:

buildFeatures {
    prefabPublishing true
}

prefab {
    mylibrary {
      headers "src/main/cpp/mylibrary/include"
    }

    myotherlibrary {
        headers "src/main/cpp/myotherlibrary/include"
    }
}

In this example, the mylibrary and myotherlibrary libraries from either your ndk-build or CMake external native build will be packaged in the AAR produced by your build, and each will export the headers from the specified directory to their dependents.

Known Issues for 4.1 Preview

This section describes current known issues in Android Studio 4.1 Preview.

Workaround for missing Kotlin plugin in Canary 9

In Android Studio 4.1 Canary 9, you may see the following error when first launching Android Studio after upgrading:

missing essential plugin org.jetbrains.android

This can happen when you import your settings from a previous version of Android Studio. Typically, this means you have a locally installed Kotlin plugin that is not compatible with the new IDE.

To fix this issue, remove the Kotlin directory from the following locations:

Linux: ~/.local/share/Google/AndroidStudioPreview4.1

Windows: C:\Users\YourUserName\AppData\Roaming\Google\AndroidStudioPreview4.1

MacOS: ~/Library/Application Support/Google/AndroidStudioPreview4.1

Because there is no Kotlin plugin compatible with Canary 9 currently available from JetBrains, we have bundled our own Kotlin plugin with the Canary 9 update, so you don't need to manually install a Kotlin plugin.

Patches not working in 4.1 Canary 2

Patches for Android Studio 4.1 Canary 2 are currently broken. To update to a newer version of Android Studio 4.1, shut down Android Studio, then download and install the latest package.

This issue has been fixed in Android Studio 4.1 Canary 3.

Timeout errors in CPU Profiler

You may experience "Recording failed to stop" errors in the Android Studio CPU Profiler when you select the Sample Java Methods or Trace Java Methods configurations. These are often timeout errors, especially if you see the following error message in the idea.log file:

Wait for ART trace file timed out

The timeout errors tend to affect traced methods more than sampled methods and longer recordings more than shorter recordings. As a temporary workaround, it may be helpful to try shorter recordings to see if the error disappears.

If you experience timeout issues with the Profiler, please file a bug that includes the make/model of your device(s) and any relevant entries from idea.log and logcat.

Git version control errors in the IDE

Operations requiring authentication in Git version control are broken in the IDE for Android Studio 4.1 Canary 1.

To fix this issue, upgrade to Android Studio 4.1 Canary 2.