编程知识 cdmana.com

New features and optimization of Android Studio 4.0

1、 Preface

Android Studio Updated again , Every major update gives us a step up in productivity , Of course, it will bring magic bug, Wall crack reminds you to upgrade carefully !!!

【 a slap in the face 】Android Studio Download link :
for Windows(64-bit) / for Linux(64-bit) / for Mac(64-bit)

This time, Android Studio 4.0 It's not easy to get the version on line , The epidemic is so serious, it is still on the way , I hope the stability is not bad . Don't talk much , Let's get down to business ,Android Studio 4.0 New functions and optimization .

2、 new function

2.1 MotionLayout And Motion Editor

This upgrade adds MotionLayout It's a real eye opener , It extends the feature rich ConstraintLayout , To help developers achieve complex animation effects in applications .

Android Studio Specially added Motion Editor send MotionLayoutI It's easier to use ,Motion Editor Can be used to create 、 Edit and preview MotionLayout Animation .

After that, there is no need to create and modify the complex xml file , Use Motion Editor You can generate , It also supports editing constraint sets , transition , Keyframe and view properties . And for those who have used ConstraintLayout For developers ,IDE It can be easily converted into MotionLayout. If you want to see the code created by the editor , Just one click .
MotionLayout Simple animation effect
Want to learn more about Motion Editor The content of , You can refer to Official documents .

2.2 Layout Validation

stay Android Studio The right column of can find the new Layout Validation tab , This is a visual layout verification tool , You can preview the layout on different devices and configurations at the same time , This helps detect layout errors and create more accessible applications .

stay Layout Validation Window , You can choose four different validation attributes :

  • Pixel Devices : Preview applications on multiple pixel devices .
  • Custom : Use custom display options ( For example, screen orientation or language ) Preview app .
  • Color Blind: Simulation preview applications using common types of color blindness .
  • Font Sizes: Preview the application with various font sizes .

Want to learn more about Layout Validation The content of , You can refer to Official documents .

2.3 Build Analyzer

Build Analyzer yes Android Gradle Plugin 4.0.0 A new build Analyzer , When will Android Studio 4.0 And Android Gradle plug-in unit 4.0.0 When used with a later version , have access to Build Analyzer Tools to show which parts of the project build process take the most time , This can be used to check the time-consuming construction caused by outdated or incorrect configuration , To optimize the time of the project construction .

To open Build Analyzer window , Please follow the steps below :

  1. If you have not yet done so , Please select from the menu bar Build> Make Project To build applications .
  2. Select... From the menu bar View > Tool Windows > Build.
  3. stay Build Window , Open in one of the following ways Build Analyzer window :
  • Android Studio When the build project is complete , single click Build Analyzer tab .
  • Android Studio When the build project is complete , single click Build Output The link on the right side of the window .

Build Analyzer The window organizes possible build problems in the tree on the left . You can check and click on each question , To investigate the details in the right side panel .

When Android Studio When analyzing the build , It will calculate a set of tasks that determine the duration of the build , And provide visualization to help you understand the impact of each task , You can also expand Warnings To get detailed information about the node .
Build Analyzer figure
Want to learn more about Build Analyzer The content of , You can refer to Official documents .

2.4 Rely on metadata

Use Android Gradle plug-in unit 4.0.0 And later when building applications , The plug-in contains metadata that describes the dependencies that have been compiled into the application ,uploading Application time ,Play The console checks this metadata to provide the following benefits :

Get about what your app uses SDK And alerts for known problems with dependencies
Get feedback that's possible to solve these problems
The data is compressed , adopt Google Play Signature key encryption , And stored in the signature bar of the published application , You can also check the metadata in the local intermediate build file in the following directory :

<project>/<module>/build/outputs/sdk-dependencies/release/sdkDependency.txt.

If you don't want to share this information , It can be done through the module build.gradle Add the following to exit the file :

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

3、 Optimize

3.1 Layout Inspector

To open Layout Inspector window , Please go to View > Tools Windows > Layout Inspector. In addition to many of the same features of the existing layout checker , The real-time layout checker also includes :

  1. Dynamic layout hierarchy( Dynamic layout hierarchy ): Update with changes to the device view .
     Dynamic layout hierarchy
  2. Property values resolution stack:( Attribute value resolution stack ): Investigate the origin of resource attribute values in source code , And navigate to its location by following the hyperlinks in the properties pane .
     Attribute value resolution stack
  3. 3D view(3D View ): At run time through advanced 3D Visualize the view hierarchy of an application , To use this function , Just in Layout Inspector Click the layout in the window and rotate it .
    3D View Want to learn more about Layout Inspector The content of , You can refer to Official documents .

3.2 CPU Profiler

CPU Profiler upgrade

Based on user feedback , Google will focus on two important ways to improve CPU Profiler User experience in .

First , Compared with the previous Android Studio Version comparison ,CPU Profiler in CPU The error rate of the record has been greatly reduced .

secondly , Yes CPU Profiler UI A comprehensive improvement has been made , To provide a more intuitive workflow , among UI Some of the notable changes include :

  • CPU The record is separated from the main profiler timeline for analysis , The recorded data is in Profiler The left side of the window is grouped .
  • For easier side-by-side analysis , Users can now view all thread activity in the thread activity timeline ( Including method , Functions and events ).
  • Flame Chart,Top Down and Bottom Up The tab for analysis is now in the right column , stay Threads In the group , For system trace, the thread will expand automatically , For other record types, it will collapse by default , Double click on the thread name ( Or by Enter) To unfold or fold them .

As shown in the screenshot , System tracking UI Also included are the following improvements :
 System tracking UI

  • Now events are in a unique color , In order to distinguish .
  • Threads are sorted by the number of trace events in them , In order to “busier” The thread of is ranked higher in the list .
  • You can select one or more threads to view the analysis only in the right column of those selected threads .
  • Again , You can select a trace event in any thread to view its analysis data .

Want to learn more about CPU Profiler The content of , You can refer to Official documents .

3.3 Smart editor for confusing code

When you write confusing code before , Probably there are more copies and pastes , And in the AS 4.0 Intelligent editor function is provided in , Not only in writing obfuscated code, there will be automatic completion of all classes , Methods and field functions , And there are also syntax highlights , Error checking and reminder functions .

When open R8 When the code contracts the rule file for ,Android Studio Now, intelligent editor function is available , for example : Grammar highlights 、 Code completion and error checking . The editor also works with Android Studio Project Integration , For all classes 、 Methods and fields provide complete symbolic completion , And includes fast navigation and refactoring .
 Smart editor for confusing code

3.4 Kotlin Android live templates

Android Studio Now include for Kotlin Class Android Real time templates . for example , Now you can type toast And press Tab Key to quickly insert Toast.

A complete list of available real-time templates , Please click from the menu bar File > Settings( Or in the macOS Up for Android Studio > Preferences ), And then navigate Editor > Live Templates.

PS: Google is right Kotlin More and more investment , If you have not learned Kotlin Little buddy , It is suggested that we should learn from it , Yes Java The basic words are still very fast , Usually mixed development , It is the fastest to master the whole battle .

3.5 Clangd support for C++

For writing C++ For language developers , Now we have clangd Finished the main language analysis engine , For code navigation , Done automatically , Error checking and prompting . And still Android Studio It contains clang-tidy. You want to configure Clangd and clang-tidy Words , Can open Setting( or Preferences), Navigate to Languages & Frameworks > C/C++ > Clangd or Clang-Tidy.

3.6 Feature-on-feature dependencies

In earlier versions Android Gradle Plug in , All dynamic function modules can only rely on the basic modules of the application .

Now? , When using Android Gradle plug-in unit 4.0.0 And later , It can include a function module that depends on another function module , namely :video The function can depend on :camera function , And the function depends on the basic module , The results are shown in the following figure .
Feature-on-feature dependencies
Dynamic features :video Depending on :camera The function of , The latter depends on the basic :app modular .

It means , When a dynamic application module is requested , The application will also download other functional modules it depends on , Create the dynamic function module after that , You can declare a functional feature dependency on a module build.gradle file , for example :video Module declaration for :camera Dependencies for :

// 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')
    ...
}

Besides , You can do this by clicking in the menu bar Help > Edit Custom VM Options And enable the following functions , stay Android Studio Enable feature-on-feature dependency function ( for example , Editing Run configuration This function is supported when ):

-Drundebug.feature.on.feature=true

版权声明
本文为[coder-ice]所创,转载请带上原文链接,感谢

Scroll to Top