By Adarsh Fernando, Product Manager

Even in these uncertain times, we’re still seeing great work from developers all over the world — and that’s one great Android app after another. Whether you’re working from a laptop in the kitchen or have a better office environment at home, you need a better, more up-to-date tool at hand: Android Studio 4.0. More efficient code writing, faster compilation speed, let you feel free to design the best application for users, download the official version now and start using!

The release of Android Studio 4.0 was made possible by early feedback from preview users. Keep reading, or watch the video below for more details on the highlights and new features of the official 4.0 release. If you can’t wait to give it a try, please go to our website to download the official Version of Android Studio 4.0.

  • Tencent Video Link

V.qq.com/x/page/q097…

  • Bilibili video link

www.bilibili.com/video/BV1cv…

design

Motion Editor

The MotionLayout API further extends the rich functionality of ConstraintLayout, enabling Android developers to manage complex motion effects and widget animations in their applications. The Motion Editor, a new addition to Android Studio 4.0, gives developers the ability to create, edit, and preview MotionLayout animations in their interface, making it easier to navigate the API. From creating files, to editing constraint Settings, transitions, keyframes, and view attributes, Motion Editor does it for you, eliminating the need to manually create and edit complex XML files — if you do need to view them, of course, with just a click of the mouse. We don’t stop there: if you’re already using ConstraintLayout, you can easily convert it to MotionLayout through the IDE. Head over to the developer website to learn more.

Create, edit, and preview animations in the Motion Editor

Layout Inspector new update

Want to know where the value of a property comes from? Or want to easily see the nesting hierarchy of views in real-time 3D? The new Layout Inspector makes this easy. It provides data that is fully synchronized with the running application and allows you to see how resources are arranged and calculated in the application, making UI debugging easier and more intuitive.

Debug the APPLICATION UI in real time with the Layout Inspector

View > Tool Windows > Layout Inspector
New UI hierarchy debugging tool in Android Studio 4.0+

Layout Validation

Use Layout Validation to compare the UI across multiple screens

Development and analysis

The CPU Profiler interface is upgraded

△ Upgraded CPU Profiler interface

CPU Profiler

The side-by-side display makes analyzing thread activity easier

Developer’s Official website

Intelligent editor functionality for writing code reduction rules

△ Smart editor function for writing R8 code rules

IntelliJ IDEA 2019.3 platform update

Android Studio IDE core has been integrated with IntelliJ IDEA 2019.3 and 2019.3.3 updates. These updates are intended to improve the overall quality and performance of the IDE.

Kotlin Android real-time template

Live Template is a handy feature in IntelliJ: you can insert common constructs into your own code by typing simple keywords. Android Studio now provides live Android-specific templates for your Kotlin code. For example, you can now quickly insert a TOAST message box simply by typing TOAST and pressing the Tab key. To see a complete list of available Live Templates, open the Settings (or Preferences) dialog box and select Editor > Live Templates.

Clangd support for C++

For developers using C++, we now use clangd as the primary language analysis engine for code navigation, completion, checking, and displaying code errors and warnings. We now also bind Clang-Tidy in Android Studio. To configure the behavior logic of Clangd or Clang-Tidy, open the Settings (or Preferences) dialog in the IDE, Choose Languages & Frameworks > C/C++ > Clangd (or Clang-Tidy) and set the appropriate options.

build

The Android Gradle plugin 4.0.0 brings Build Analyzer functionality to Android Studio by using the Java 8 API (regardless of the lowest API level of your application). It also supports the creation of function-to-function dependencies between dynamic functional modules. For a complete list of updates, see the Android Gradle plugin version 4.0.0.

Build Analyzer

Use Build Analyzer to find Build performance bottlenecks

Developer’s Official website

Java 8 Language library bytecode Conversion in D8 and R8 (desugaring)

The previous version of Android Gradle plug-in supported a number of Java 8 language features, such as lambda expressions and method references, at all API levels through bytecode conversion operations. The bytecode conversion engine has been extended in Android Studio 4.0, and now regardless of the minSdkVersion of your application, Java 8 apis (such as java.util.stream, java.util.function, and java.time) are available. Head over to the developer website to learn more.

Functional module level dependencies

▽ Function depends on function

Developer’s Official website

New build function switch options

The Android Gradle plug-in has built-in support for modern code libraries (such as data binding and view binding) and build functionality (such as auto-generating BuildConfig classes). But you may not need these libraries and features for every project. In version 4.0.0 of the plug-in, you can individually turn off a build option (as shown below) to optimize build performance for large projects. For DSLS and a complete list of features you can manipulate, see the release notes.


android {
    // The default value foreach feature is shown below. // You can change the value to override the default behavior. buildFeatures { // Determines  whether to support View Binding. // Note that the viewBinding.enabled property is now deprecated. viewBinding =false
        // Determines whether to support Data Binding.
        // Note that the dataBinding.enabled property is now deprecated.
        dataBinding = false. }}Copy the code

Android Gradle plugin DSL for enabling/disabling build functionality

Basic support for Kotlin DSL script files

Android Studio 4.0 now has built-in support for Kotlin DSL build script files (*.kts), which means that Kotlin build scripts have full quick fixes and can operate in the Project Structure window. While we have high expectations for configuring builds using Kotlin, we will continue to improve the DSL API for the Android Gradle plugin over the next year, which may bring a major breaking change to the API for Kotlin script users. In the long run, these improvements should make DSLS easier to use for Kotlin script users.

Dependency metadata

When building an application using the Android Gradle plugin version 4.0.0 and above, the plugin contains metadata that describes the library dependencies compiled into your application. When you upload your app, the Play Console checks this metadata and tells you which SDKS and dependencies in your app are problematic, and in some cases gives you feedback on how to fix them.

The data is compressed, encrypted with Google Play’s signature key, and stored in the signature module of the published app. If you don’t want to share this information, you can add the following to your module’s build.gradle file:


android {
    dependenciesInfo {
        // Disables dependency metadata when building APKs.
        includeInApk = false
        // Disables dependency metadata when building Android App Bundles.
        includeInBundle = false}}Copy the code

Disable dependency metadata in APK or App Bundle

Now let’s review the improvements and new features Android Studio 4.0 brings:

Design:

  • Motion Editor: Easily create, edit, and preview MotionLayout animations
  • Layout Inspector new update: More intuitive real-time debugging experience
  • Layout Validation: Compare the UI on multiple screens simultaneously

Development and analysis:

  • CPU Profiler update: UI is more intuitive, easier to navigate, and data is easier to read
  • R8 Rule update: Write smart editor features for code reduction rules, such as syntax highlighting, completion, and error checking
  • IntelliJ IDEA 2019.3 Platform update: Improved performance and quality
  • Live Template Update: Android specific live template for Kotlin
  • Clangd support: Clangd and Clang-Tidy are enabled by default

Construction:

  • Build Analyzer: Understands and finds performance bottlenecks at Build time
  • Java 8 language support update: Java 8 apis are now available regardless of the application’s lowest API level
  • Function-to-function dependencies: Define the dependencies between two dynamic functional modules
  • BuildFeatures DSL: Enable/disable build functionality, such as data binding, one by one
  • Kotlin DSL: Basic support for Kotlin DSL script files

See the release notes for complete information on this release.

Start using now

Go to the download page for Android Studio 4.0. If you’re using an older version of Android Studio, you can update directly to the latest version.

As always, we look forward to your feedback, and if you like a feature or find a problem, feel free to let us know.