We’re excited to release Stable Version 4.1 of Android Studio, bringing you a range of features for common editing, debugging, and optimization tasks. One of the key claims of version 4.1 is to help you follow best practices and code efficiently when using the Android Jetpack library, Android’s suite of development libraries. Based on the feedback, we integrated a number of common Android libraries directly into the IDE to improve the experience of writing code.

Some of the highlights of Android Studio 4.1 include the introduction of a new Database Inspector, which can be used to query an application’s Database; Support for browsing projects that use Dagger or Hilt for dependency injection; Support for using the TensorFlow Lite model in Android projects further enhances support for device-side machine learning. We also updated Apply Changes to speed up deployment. We’ve made some changes based on feedback, introducing a new native memory performance analyzer and standalone analytics tools to help game developers.

Product quality remains the team’s main focus, and we are constantly working to address bugs and performance issues. Based on the feedback we received, many developers were impressed by our focus on improving performance and reliability. We are pleased to report that in this release cycle, we fixed 2,370 bugs and resolved 275 public issues. High quality is our goal, because we know it’s the key to making developers more productive.

Thanks to many users who provided early feedback in the preview. Thanks to your feedback, features in Android Studio 4.1 have been iterated and improved. If you’re ready to use this new stable release with a series of new features to increase productivity, you can download and start using it here.

Here’s a list of all the new features in Android Studio 4.1 by key development process.

design

Material Design component update

The Android Studio template in the Create New Project dialog now uses the Material Design component (MDC) and supports the latest version of the theme and style Design guide by default. This makes it easier for developers to use the recommended Material style pattern and support modern interface features such as dark themes.

Update the Material Design component in the project template

The updates include:

  • MDC: Project usebuild.gradleIn thecom.google.android.material:material. Basic application theme usageTheme.MaterialComponentsParent and override the updated MDC color and “on” attribute.
  • Color resourcescolors.xmlUse a literal name for the color resource inpurple_500Rather thancolorPrimary).
  • Theme resource: Theme resources are locatedthemes.xml(rather thanstyles.xml) and useTheme.<ApplicationName>The name.
  • The dark theme: Basic application themesDayNightParent, and divided intores/valuesAnd res/values-night.
  • The theme attribute: Refer to color resources as theme properties in layouts and styles (e.g? attr/colorPrimary) to avoid hard-coding colors.

The development of

Database Inspector

With the new Database Inspector, we hope to simplify checking, querying, and modifying the application Database. First, deploy your application to a device running API 26 or higher, then choose View > Tool Windows > Database Inspector from the menu. Whether your application uses the Jetpack Room development library directly or the Android version of SQLite, you can now easily check the databases and tables in your running application or run custom queries.

Because Android Studio keeps the connection alive while you inspect the application, you can also use the Database Inspector to modify the values and see the results in the running application. If you use the Room persistence library, Android Studio also inserts a run button next to each Query in the code editor to help you quickly run the Query defined in the @Query annotation. You can read the official documentation for details.

Use the Database Inspector to inspect, query, and modify the application Database

Run the Android emulator directly from Android Studio

You can now run the Android emulator directly from Android Studio. This feature helps save screen space by allowing you to use hotkeys to quickly navigate between emulator and editor Windows and organize your IDE and emulator workflows in a single application window. You can manage common emulator operations like snapshots and rotations and screenshots in Studio, but you still need a stable emulator to use the full range of functional options. You can enable this feature by following the menu path: File → Settings → Tools → Emulator → Launch in Tool Window.

Run Android Emulator in Android Studio

Dagger navigation support

DaggerDependency injection library is a common dependency injection library on Android. Android Studio provides a new gutter operation and extends support in the Find Lead window to make navigating between the Dagger related codes easier. For example, click next to the method using the given typeThe gutter operation will navigate you to the location that provides that type. Instead, clickThe gutter operation navigates you to the place where the type is used as a dependency. Android Studio also supports the use of JetpackHiltLibrary-defined dependencies perform navigation operations. You can readThe official documentationLearn more.

Navigate between the Dagger related codes using the gutter operation

Use the TensorFlow Lite model

Android developers are using machine learning to create new and useful experiences. TensorFlow Lite is a common development library for writing mobile machine learning models, and we want to simplify the process of importing these models into Android applications. Similar to view binding, Android Studio generates easy-to-use classes that help you streamline the code needed to run your model and improve type safety. Current implementations of ML Model Binding support image classification and style transformation models, provided they are enhanced by metadata.

To see details about imported models and how to use them in your application, double-click the.tflite model file in your project to open the model viewer page. You can read the official documentation for details.

View TensorFlow Lite model metadata in Android Studio 4.1

Build and test

Android Emulator – Foldable device hinge information support

Android Studio

In addition to the recent addition of 5G mobile network testing capabilities, we’ve also added support for foldable devices to the Android emulator. In Android emulator 30.0.26 and later, you can set up a foldable device using a variety of foldable designs and configurations. Once set up, the simulator provides hinge Angle sensors and attitude change information so you can test the response of the application on these models. See the blog post “Developing on Android 11 using an Android Emulator” for more.

Apply Changes to update

Faster builds help developers change applications more easily and quickly. To help you iterate more efficiently, we’ve made several enhancements to Apply Changes for Android 11 and later devices.

We invested heavily in optimizing the speed of iteration and developed a way to deploy and save changes on devices without installing applications. Now, after the initial deployment, subsequent deployments to Android 11 devices can be made much faster with Apply Code Changes or Apply Changes and Restart Activity. We also added support for other code Changes in Apply Changes. Now, after you add a method, you can click the Apply Code Changes or the Apply Changes and Restart Activity button to deploy those Changes to your running application.

Export C/C++ dependencies from an AAR

Android Gradle Plugin 4.0 adds the ability to import Prefab packages into AAR dependencies. We want to extend this functionality to share native libraries. AGP 4.1 supports shipping libraries from external native builds in an Android library project AAR. To export the native library, add the following to the Android block of the library project build.gradle file:

buildFeatures {
    prefabPublishing true
}

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

    myotherlibrary {
        headers "src/main/cpp/myotherlibrary/include"}}Copy the code

Native code crash reports symbolic resolution

When a crash or ANR occurs in native code, the system generates a stack trace, which is a snapshot of the sequence of nested functions called before the program crashed. These snapshots can help you identify and fix problems in the source code, but they must first be symbolized to convert computer addresses back to human-readable function names.

If your app or game was developed using native code such as C++, you can now upload the debug symbol file for each version of your app to the Play administration. The Play Manager uses these debug symbol files to symbolize the stack traces of your application, simplifying crash and ANR analysis. To include debug symbols in your App Bundle, add the following to your project’s build.gradle file:

android.buildTypes.release.ndk.debugSymbolLevel = 'SYMBOL_TABLE'
Copy the code

To optimize the

System Trace interface improved

In Android Studio 4.1, we’ve overhauled System Trace, an optimization tool that lets you see how your application is using System resources in real time. Box-selected mode also makes it easier to select trace records, and we’ve added new analysis tabs and more frame rendering data to help you investigate rendering problems in your application interface. You can read the official documentation for details.

Box Selection: In the Threads section, you can now drag the mouse to box a rectangular area and click the Zoom to Selection button in the upper right corner (or use the keyboard shortcut M) to Zoom in on the area. When you drag and drop similar threads together, you can box select across multiple threads to examine all threads at once.

Box selection mode makes it easier to select trace records

Summary TAB: The new Summary TAB in the Analysis panel displays the following:

  • Summary statistics for all instances of a particular event, such as instance count and minimum/maximum duration.
  • Trace event statistics for selected instances.
  • Data about thread state distribution.
  • The longest running instance within the selected trace event.

△ View Summary statistics in the Summary TAB

Display data: In the Display section, new timelines for SurfaceFlinger and VSYNC help you investigate rendering problems in the application interface.

Independent analyzer

You can now access the Android Studio profiler in a separate window from the Main Android Studio window. This feature is useful when optimizing Android games built using other tools, such as Unity or Visual Studio.

To run a standalone analyzer, do the following:

  1. Make sure your system is not currently running profilers in Android Studio.

  2. Go to the installation directory and navigate to the bin directory:

Windows/Linux

 <studio-installation-folder>\bin

macOS

 <studio-installation-folder>/Contents/bin

  1. Depending on your operating system, runprofiler.exe 或 profiler.sh

Standalone analyzers can be connected to the Android Emulator or other connected devices.

Optimize your application with a standalone Android Studio profiler

Native memory performance analyzer

Tracking native memory usage is important for game developers and other developers using C++ to optimize memory usage in their applications. The Android Studio Memory Profiler now includes a Native Memory Profiler for applications running on Android 10 and later physical devices. The native memory performance analyzer tracks the allocation/destruction of objects in native code over a specific period of time and provides information on overall memory allocation and the remaining size of the system heap.

To start recording, click Record Native Allocations at the top of the Memory Profiler window:

Use native memory profiler to view native memory allocation

conclusion

To recap, Android Studio 4.1 includes the following new and improved features:

design

  • Material Design component update

The development of

  • Database Inspector
  • Run the Android emulator directly from Android Studio
  • Dagger navigation support
  • Use the TensorFlow Lite model

Build and test

  • Android Emulator – Foldable device hinge information support
  • Apply Changes to update
  • Export C/C++ dependencies from an AAR
  • Native code crash reports symbolic resolution

To optimize the

  • System Trace interface improved
  • Independent analyzer
  • Native memory performance analyzer

Scott Swarthout is product Manager

The material in this article is not sponsored by or associated with Unity Technologies or its affiliates. “Unity” is a trademark or registered trademark of Unity Technologies or its affiliates in the United States and elsewhere.