Android Studio 4.0 new features and upgrade exception


On 2020.05.30, I upgraded Android Studio 3.6.3 to Android Studio 4.0. Compared with stability, I always like to constantly upgrade plugins and Gradle, hoping to try new things in advance to bring new powerful features and experiences, although Step on the pit^-^, but still enjoy it.

1. Upgrade issues

1. dataBinding open configuration modification

After upgrading to AS 4.0, the following warning appears, which is unbearable for people like me with code cleanliness and must be resolved

DSL element 'android.dataBinding.enabled' is obsolete and has been replaced with 'android.buildFeatures.dataBinding'

Solution:

    dataBinding {
    
    
        enabled = true
    }

This is the original DataBinding opening method. After the upgrade, replace it as follows:

    buildFeatures{
    
    
        dataBinding = true
        // for view binding :
        // viewBinding = true
    }

viewBinding 也是一种控件绑定的技术,我还是认为dataBinding 更强大

2. Missing essential plugin:org.jetbrains.android

Unlike 3.6 + configuration is not the same, can not refer to the old C after upgrade AS 4.0: \ Users \ Administrator.AndroidStudio3.6 \ config The config
Insert picture description here
want to solve this problem, two ideas:

  1. Delete the config folder C:\Users\Administrator.AndroidStudio3.6\config
  2. Do not use the original config when the AS upgrade is completed and restart, and redo the personalized idea settings

3. Android studio 4.0 cannot set offline build

After upgrading to 4.0, android studio no longer has the option of offline gradle, as shown in the figure:
Insert picture description here
Version 4.0 requires us to manually enter commands in Terminal. I don’t know if the
operation steps will be changed in subsequent versions . Enter the project root directory and enter gradlew build --offline to enter offline build mode, if you want to exit, enter gradlew build to enter online mode
Insert picture description here

在我的评论区里有一位兄弟"猫头"提醒了我,Gradle的在线离线编译功能有一个更加方便的开关按钮,在项目打开后的右边Gradle菜单中,如图中标注有一个Gradle的在线离线开关,请各位看官注意。——更新于20200725
Insert picture description here

Two, Android Studio 4.0 new features

1. Gradle build optimization

When using Android Studio 4.0 with Android Gradle plugin 4.0.0 and higher, the "Build Speed" window can be used to help you understand and diagnose issues during the build process, such as disabled optimizations and incorrectly configured tasks. After we use View> Tool Windows> Build, we can see that the Build Analyzer has our build analysis report under AS

2. Layout Inspector optimization

Use the updated real-time layout checker to debug layouts to provide complete, real-time insights when deploying the app’s UI to devices. Layout Inspector 是取代Hierarchy Viewer的UI优化神器

To open the "Layout Inspector" window, go to "View> Tool Windows> Layout Inspector". In addition to many of the same functions of existing layout checkers, the real-time layout checker also includes:

  1. Dynamic layout hierarchy, the hierarchy will be updated as the device view changes.
  2. The attribute value resolution stack can investigate the original location of the resource attribute value in the source code and navigate to its location.
  3. Advanced 3D visualization of the view hierarchy of the application at runtime.

3. CPU Profiler UI Sheng ji

The UI of the CPU Profiler has been completely revised to provide a more intuitive workflow. Some notable changes include:

  1. The CPU record is now separated from the main profiler timeline for easy analysis.
  2. The recorded data is organized in groups on the left side of the Profiler window. You can move the group up and down to reorganize the list.
  3. To make side-by-side analysis easier, you can now view all thread activity in the thread activity timeline. To expand a specific thread and view its activity, double-click that thread in the timeline.

4. System Trace UI upgrade

Similarly, the UI of System Trace has also been updated:

  1. Now, the event has a unique color to make it easier to distinguish.
  2. Threads are sorted by the number of trace events in them, so that "busier" threads are ranked higher in the list.
  3. You can select one or more threads to view the analysis only in the right column of those selected threads. Clicking on an event also displays an analysis of the selected event in the right column.

5. Java 8 library desugaring in D8 and R8

Through a process called desugaring, you can now use many Java 8 language APIs without having to set a minimum API level for your application. This means that you can now include standard language APIs that are only available in recent Android versions (e.g. java.util.streams) in applications that support older versions of Android.
That is 以后对于低版本Android项目也能支持java8了, as my highest version SDK = 19, it also supports the Java 8 the Lambda's
Insert picture description here
Insert picture description here
want to cancel configurable support for Java 8 in the gradle.properties

android.enableDesugar=false

6. Basic support for Kotlin DSL script KTS files

Android Gradle plugin 4.0.0-alpha01 and later versions now support Kotlin DSL build script files (*.kts). When using Android Studio, certain IDE features (such as the "Project Structure" dialog box and the build script quick fix) now also support reading and writing Kotlin build script files.
AS 4.0开始自动默认支持kotlin,也即即使项目未进行Kotlin依赖,也能进行Kotlin文件的创建编译

7. Smart editor function for code shrinking rules

When you open R8's code shrinking rules file, Android Studio now provides smart editor functions, such as syntax highlighting, code completion, and error checking. The editor is also integrated with your Android Studio project to provide complete symbol completion for all classes, methods and fields, including quick navigation and refactoring.

8. New Action Editor

Android Studio now includes a visual design editor for the MotionLayout layout type, making it easier to create and preview animations.
In previous versions, creating and changing these elements required manual editing of constraints in the XML resource file. Now, the motion editor can generate this XML for you, and supports start and end states, keyframes, transitions, and timelines.
MotionLayout 是个非常新控件,功能强大可用

9. Dynamic-feature support

In order to support the use of dynamic feature plugins (com.android.dynamic-feature) to build and package instant apps using Android application bundles, the Android Gradle plugin 4.0.0-alpha01 and later versions remove the feature plugin (com.android.feature) ) And Instant App plugin (com.android.instantapp).

Therefore, to use the latest Android Gradle plugin, you need to migrate instant apps to support Android App Bundles. By migrating instant applications, you can take advantage of application bundles and simplify the modular design of applications.

10. Kotlin Android Live Template

Android Studio now includes Android live templates for your Kotlin class. 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> Editor> Live Templates.

11. Layout Validation

Layout verification is a visual tool that can be used to preview layouts on different devices and configurations at the same time, helping you detect layout errors and create more accessible applications.
You can preview the layout using one of the following configuration sets:

  1. Pixel device
  2. customize
  3. Color blindness
  4. Font size
    To use this function, when viewing the layout file in the code editor, click the "Layout Verification" tab and window in the upper right corner of the IDE.

12. Fragment and template

Now you can use the Create new destination wizard and the new fragment template by navigating to "File"> "New"> "Fragment"> "Gallery" or clicking "Create New Destination" in the "Navigation" editor .

13. Dependencies metadata

When building an application with the Android Gradle plugin 4.0.0 and higher, the plugin contains metadata describing the dependencies that have been compiled into the application. When uploading an application, the Play Console will check this metadata to provide you with the following benefits:

  1. Get alerts about known issues regarding SDK and dependencies used by the application
  2. Receive actionable feedback to solve these problems

The above is a summary of some new features of AS 4.0, and some questions and solutions encountered during the upgrade process.

Blog writing is not easy, if you think the article is okay, please like it ^ _ ^!

Related Links

  1. Android Studio update失败问题 some conflicts were found in the installation area
  2. Attr/pivotX and attr/pivotY exception report solutions
  3. SecurityException: Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE
  4. The most comprehensive Android studio plugin in history
  5. Analysis of sorting algorithms for common interviews

Guess you like

Origin blog.csdn.net/luo_boke/article/details/106437158