Author:wanbo
Address:https://juejin.im/post/5db8cee351882557134d0411
The new Android Studio 4.0 features a completely revamped startup interface. Today, at Google I/O, the official beta version of Android Studio 3.5 was released, followed by the beta version of Android Studio 3.6 a month later. Recently, at the Android Dev Summit, we were introduced to the preview version of Android Studio 4.0. Today, let’s take a look at what new experiences Android Studio 4.0 brings to developers!
Next, I will introduce the latest developments in Android Studio 4.0 based on the content shared at the Android Dev Summit and my own understanding. If you haven’t followed yet, remember to subscribe! If you find these articles interesting, please share, forward, comment, and like!
Compilation and Build
The new Build window now shows a new Build Speed window after each build, where we can view the time taken by different plugins and tasks during the entire build process. This allows for targeted fixes. It will also inform us which plugins are executed every time we build, helping us identify issues and reduce unnecessary plugin executions to shorten build time. There are many classifications here, and those interested can study them one by one.
In previous articles, I shared some excellent Kotlin projects, including a Gradle official open-source Kotlin-DSL-sample. You can find the article here: Selected Kotlin Open Source Projects of the Week.
Now, Android Studio 4.0 has improved code suggestions for Kotlin Gradle DSL, allowing us to view DSL documentation directly in the IDE. We all know that in the previous default Groovy syntax, Android Studio automatically helped us check if there were new versions of existing dependencies. This feature has also been retained for Kotlin Gradle DSL.
In terms of compilation, a new coreLibraryDesugaringEnabled true directive has been added. By enabling this directive, we can use certain advanced APIs from Java 8.
For example, as shown in the image above, the list.stream() method can only be used on API 24 and above by default. By enabling coreLibraryDesugaringEnabled, we can eliminate version restrictions, allowing this method to be used on devices below API 24. Currently, this directive supports java.util.stream, java.time, java.util.function, ConcurrentHashMap, etc. The purpose of this feature is to resolve persistent bugs that cannot be fixed due to the inability to use Java advanced APIs on older versions.
The new Android Studio 4.0 provides syntax highlighting, code suggestions, and error checking when editing ProGuard files. Additionally, when refactoring names, corresponding fields in ProGuard files will be updated in real-time.
A new viewBinding directive has been added. When we enable it, the compiler will generate a view binding class for us, such as ActivityMainBinding shown in the image below.
The purpose of viewBinding is to ensure that the Views we use in our code actually exist in the layout, preventing crashes caused by using findViewById on null references. (However, I couldn’t enable it successfully on 4.0 canary 1, there should still be bugs 😂)
View Features
Currently, we have three ways to write UI: XML, code to write custom Views, and Jetpack Compose. All three methods support preview in Android Studio 4.0.
The preview interface for all three methods is the same, divided into three modes: edit, preview, and edit + preview. Not to mention, the support for previewing custom Views is incredibly convenient and greatly enhances development efficiency.
Moreover, the XML view preview supports simultaneous previews on various devices with different resolutions, and it can also preview the layout situation in different languages for internationalization, as well as support for color-blind modes. (Of course, the last two features have not yet appeared in 4.0 canary 1, they were only explained in the official demo video)
Another amazing feature is that Android Studio 4.0 supports embedded simulators. Note that the image interface above is not the preview interface we mentioned first, but a real simulator, allowing for simultaneous development and debugging without switching screens.
The Layout Inspector has also been updated. The previous Layout Inspector was similar to a layout snapshot, requiring a restart after switching interfaces. In Android Studio 4.0, the Layout Inspector supports real-time auto-update. When we switch pages on our devices, the layout analyzer will also update, and the display of resource files is more complete, adding complete call chain information. There is also an amazing feature (highlighted!) where the Layout Inspector supports 3D model inspection, as shown in the image below:
Although the official video mentions that all these features will appear in Android Studio 4.0, as far as I can tell from the canary 1 version I currently have, the custom View preview, embedded simulator, and new Layout Inspector have not yet been found. Subsequent canaries should gradually support these features.
Animation Features
In a previous post, I introduced:How many of the 8 animations in Android have you used? The last one is MotionLayout, but I also mentioned at the time:
Using MotionLayout requires us to customize MotionScene in XML, specifying the changes between different layouts in MotionScene.
After seeing the official demo, to be honest, this way of writing animations is still somewhat cumbersome. Fortunately, this time Android Studio 4.0 supports a new animation editor that allows us to create MotionLayout animations through visual operations.
We can specify the layout states at the start and end, set the duration of the animation, and click the Transition line above to preview the animation. Isn’t that very simple! We can also add keyframes at any point during the duration, setting the state for each frame, allowing for finer control over animation effects. Keyframes can set properties and relative positions. With MotionLayout and the new animation editor, the only limit to creating animations on Android is your imagination.
Others
The new Resource Manager supports viewing and managing various resources, such as images, colors, layouts, strings, animations, etc.
The built-in Material Design Icon provides multiple style options: fill, line, two-color, rounded, rectangle, no more need to cut images yourself 😂.
The IDE has built-in many shorthand code directives to help us use them quickly, and it also supports custom inserts. After watching this sharing, I realized that I have only been at the stage of using Android Studio, never delving deeper. For example, I only recently discovered that I can use File → New → Import Sample to view the best practice code provided by the official, including AAC architecture, animations, CameraX, NDK, and various categories.
That’s all for this part of the latest developments in Android Studio shared at the Android Dev Summit. Of course, behind these features, the IDE itself has greatly improved memory usage and compilation speed; otherwise, it wouldn’t have jumped directly to version 4.0. Just think about it, Apple’s Xcode has already reached version 11, and Android Studio is just at 4.0. It’s truly a case of slow work yielding fine results.
—END—
Recommended Reading:
Elegantly Handling Chaotic Data Returned from Background in Android
The Most Comprehensive Android Memory Optimization Techniques
Custom View: Kotlin Drawing Simplified Xiaomi Time Widget MIClockView

