Android Studio 4.0 (May 2020) is updated with a variety of new features and improvements, as well as some deprecated features.
Important: After the update, you will need to restart Android Studio to apply all memory Settings migrated from earlier versions of the IDE. For more information, see the Known Issues page.
Android Gradle plugin 4.0.0
The latest version of The Android Gradle plug-in contains many updates, such as Java 8 that update dependencies on older versions of Android functionality. For more information can be read the full Android Gradle plug-in release notes 】 (android.devsite.corp.google.com/studio/rele…). .
In addition, new features in Android Studio can help you improve build performance.
1. Build profilers
When used with Android Studio 4.0 and Android Gradle plugin 4.0.0 and higher, the Build Analyzer window helps you understand and diagnose problems during the Build process, such as disabled optimizations and incorrectly configured tasks. To open the Build Analyzer window, follow these steps:
- 1. If you have not already done this, Build the application by selecting Build> Make Project from the menu bar.
- 2. Choose View > Tool Windows > Build from the menu bar.
- 3, inBuildWindow, open in one of the following waysBuild AnalyzerWindows:
- After Android Studio has finished building the project, click the Build Analyzer TAB.
- After Android Studio has finished building the project, click the link to the right of the Build Output window.
The Build Analyzer window organizes possible Build problems in the tree on the left. You can examine and click on each issue to investigate its details in the right panel.
When Android Studio analyzes a build, it calculates a set of tasks that determine the duration of the build and provides visualizations to help you understand the impact of each task. You can also expand the Warnings node to get detailed information about Warnings.
Check the tasks that determine the build duration.
2. Java 8 libraries are disappearing in D8 and R8
Android Studio now supports the use of multiple Java 8 language apis without having to set a minimum API level for applications.
Through a process called desugaring, the DEX compiler D8 in Android Studio 3.0 and later has provided substantial support for Java 8 language features such as lambda expressions, default interface methods, try resources, and so on.
In Android Studio 4.0, the desugaring Engine has been extended to be syntactic sugar for Java language apis. This means that you can now include standard language apis that are only available in the latest versions of Android in java.util.Streams applications that support older versions of Android.
This release supports the following set of apis:
- Sequential streams (
java.util.stream1
) - A subset of
java.time
java.util.function
- Recent additions to
java.util.{Map,Collection,Comparator}
- Optionals (
java.util.Optional
.java.util.OptionalInt
and some other new classes useful with the above APIs - Some additions to
java.util.concurrent.atomic
(new methods onAtomicInteger
.AtomicLong
and AtomicReference) ConcurrentHashMap
(with bug fixes for Android 5.0)
To support these language apis, D8 compiles a separate library DEX file that contains some implementations that lack the API themselves and includes them in your application, and the procedure desugaring rewrites your application code to use the library at run time.
To enable support for these language apis, include the following in the module build.gradle file:
android {
defaultConfig {
// Required when setting minSdkVersion to 20 or lower
multiDexEnabled true
}
compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
// Sets Java compatibility to Java 8
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
coreLibraryDesugaring 'com. Android. The tools: desugar_jdk_libs: 1.0.4'
}
Copy the code
3. Functional dependencies
In earlier versions of Android Gradle plug-ins, all dynamic functional modules depended only on the base modules of the application.
Now, when using Android Gradle plugin 4.0.0 and later, you can include a feature module that depends on another feature module, i.e. :video can depend on the :camera feature, and the feature depends on the base module, as shown below.
Dynamic function :video depends on :camera function, the latter depends on the basic: APP module.
This means that when an application requests to download a dynamic feature module, the application will also download other feature modules that it depends on, and then create dynamic feature modules later. You can declare a feature on the module that depends on the build.gradle file. For example, the video module declares a dependency on :camera:
// In the build.gradle file of the ':video' module.
dependencies {
// All dynamic feature modules must declare a dependency
// on the base module.
implementation project(':app')
// Declares that this module also depends on the 'camera'
// dynamic feature module.
implementation project(':camera')... }Copy the code
In addition, you can enable feature-on-feature Dependency in Android Studio by clicking Help > Edit Custom VM Options in the menu bar and enabling the following functionality (for example, Support this when editing Run Configuration) :
-Drundebug.feature.on.feature=true
Copy the code
4. Rely on metadata
Building an application using the Android Gradle plug-in 4.0.0 or higher contains metadata describing dependencies that have been compiled into the application. This metadata is checked by the Play console during a uploading application providing the following benefits:
- Get alerts about known problems with the SDKS and dependencies your app uses
- Receive actionable feedback to solve these problems
The data is compressed, encrypted with the Google Play signature key, and stored in the signature bar of the published app, or you can check the metadata yourself in a local intermediate build file in the following directories: The < project > / < module > / build/outputs/SDK – dependencies/release/sdkDependency. TXT.
If you do not want to share this information, you can exit by adding the following to the module 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
Support Kotlin DSL script files
The Android Gradle plugin now supports Kotlin DSL build scripts (*.kts). When used with Android Studio, Some IDE features, such as the Project Structure dialog and build script quick fix, now also support reading and writing Kotlin build script files.
CPU Profiler upgrade
Based on user feedback, Google will focus on improving the user experience in CPU Profiler in two important ways.
First, the error rate of CPU logging in the CPU Profiler has been significantly reduced compared to previous versions of Android Studio.
Second, the CPU Profiler UI has been overhauled to provide a more intuitive workflow, with some significant changes to the UI including:
-
CPU records are separated from the main Profiler timeline for analysis, and recorded data is distributed in groups on the left side of the Profiler window. Users can click the options icon in the profiler
Reorganize the list by moving groups up and down in the options icon icon in the upper right corner of the window or by dragging and dropping individual items in the group.
-
To make side-by-side analysis easier, users can now view all thread activity (including methods, functions, and events) in the thread activity timeline. There are several ways to browse the timeline:
- To focus on a specific point in time, drag a range in the upper left of the CPU usage chart.
- To zoom in or out, use the mouse wheel while holding down Control (or Command on MacOS); To pan left or right, drag while holding down the space bar.
- Or use the W and A keys for fine zooming in and out, and the S and D keys for fine panning left and right.
-
The Flame Chart, Top Down and Bottom Up analysis tabs are now in the right column. In the Threads group, the Threads are automatically expanded for system trace records and collapsed by default for other record types, Double-click (or press Enter) on the thread names to expand or collapse them.
-
As the screen capture shows, the system trace UI also includes the following improvements:
- Events are now color-coded to make them easier to distinguish.
- Threads are sorted by the number of trace events in them so that “busier” threads rank higher in the list.
- You can select one or more threads to view analysis only in the right column of those selected threads.
- Similarly, you can select a trace event in any thread to view its analysis data.
4. Design tools
This version of Android Studio includes updates to design tools, such as the Layout Inspector and the new Motion Editor.
1. New Action editor
Android Studio now includes a visual design editor for the MotionLayout layout type, making it easier to create and preview animations.
The Action Editor provides a simple interface for working with elements in the MotionLayout library that are the basis for animations in Android applications.
In previous versions, creating and changing these elements required manual editing of constraints in the XML resource file. The motion editor can now generate this XML for you, with support for start and end states, keyframes, transitions, and timelines.
For more information on how to use the Motion editor, see the User’s guide.
⚠️ Note: Before using the Motion editor, be sure to set the ConstraintLayout dependency in the file to build.gradle as version 2.0.0-beta3 or higher.
2. Live Layout Inspector
Use the Live Layout Inspector to debug layouts, providing complete real-time updates to the application UI as it is deployed to the device.
To open the Layout Inspector window, go to View > Tools Windows > Layout Inspector. In addition to many of the same features of existing layout inspectors, the real-time layout inspector includes:
- Dynamic Layout Hierarchy: Updates as the device view changes.
- Property values resolution stack: Investigate the origin of resource Property values in the source code and navigate to their location by following the hyperlinks in the properties pane.
- 3D View: View the view hierarchy of your application at runtime through advanced 3D visualization. To use this feature, simply click on the Layout in the Layout Inspector window and rotate it.
Use the Live Layout Inspector only when deploying your application to a device or emulator running API level 29 or higher. To enable the Live Layout Inspector, go to File > Settings > Experimental, Then check the box next to Enable Live Layout Inspector, and then click the check box next to Layout Display above Live Updates.
3. Layout verification
Layout Validation is a visual tool that can be used to simultaneously preview layouts on different devices and configurations to help detect Layout errors and create more accessible applications.
Users can access this functionality by clicking on the Layout Validation TAB in the upper right corner of the IDE window:
In the Layout Validation window, you can select from four different configuration sets:
- Pixel Devices: Preview apps on multiple Pixel Devices.
- Custom: Previews the application with Custom display options, such as screen orientation or language.
- Color Blind: Analog preview application that uses common types of Color blindness.
- Font Sizes: Preview applications using a variety of Font Sizes.
For more information about using Layout validation, see Debugging layouts with Layout Inspector.
Smart editor features for code shrink rules
Android Studio now offers smart editor features such as syntax highlighting, code completion, and error checking when opening R8’s code shrink rule file. The editor also integrates with the Android Studio project to provide complete symbol completion for all classes, methods, and fields, and includes quick navigation and refactoring.
Kotlin Android Real-time template
Android Studio now includes Android live templates for Kotlin classes. For example, you can now type Toast and press Tab to quickly insert toast.
For a complete list of available Live Templates, click File > Settings (or Android Studio > Preferences on macOS) from the menu bar, and then navigate to Editor > Live Templates.
Fragment Wizard and New Fragment Templates
The New Android Fragment Wizard wizard and the New Fragment template are now available when you navigate to File > New > Fragment > Gallery or click Create New Destination in the Navigation editor.
8. Extended camera support in Android emulator
The Android Emulator camera includes the following new features when using Android 11 images:
- RAW shooting
- YUV post-processing
- Level 3 devices
- Logical camera support
To learn more about developing for the next release of Android, go to the Android 11 Developer Preview user documentation.
Clangd is now available in the C ++ code editor
Jetbrains CLion is a technology that supports Android Studio C ++ language support and now uses an inspection engine based on LLVM Clangd and Clang-Tidy to speed up C/C ++ code completion, And provides more seamless integration with Clang-Tidy.
Now available in the Android Studio C++ code editor, clangd and clang-tidy are both part of the open source LLVM additional tools:
- Clangd has code completion capabilities to compile error messages and locate navigation in the editor.
- Clang-tidy is a C ++ Linter tool with an extensible framework for diagnosing and fixing typical programming errors.
In previous versions, Android Studio users could use Clang-Tidy via NDK; With this change, Android Studio no longer relies on the NDK’s clean features.
Dir setting in local.properties is deprecated
Dir should no longer be set in the application’s local.properties file, and support for this setting will be removed in future releases. The Android Gradle plugin sets the NDK version by default, but if you need a specific version of the NDK, you can set build.gradle in Android.ndkVersion.
For more information about setting up the NDK, see Install and configure the NDK and CMake.
11. IntelliJ IDEA 2019.3.3
The core Android Studio IDE has been updated and improved with IntelliJ IDEA until version 2019.3.3.