YACINE REZGUI: Android Studio version 4.0
is now available for download on the Stable channel.
This new version of Android Studio
add new features, a new Motion Editor, Build Speed window,
Live Layout Inspector, Multi Preview for your layout,
support for Kotlin DSL script files
and a Smart Editor for R8 rules.
Android Studio 4.0 includes a visual design editor
for the MotionLayout type, making it easier
to create and preview animations.
The Motion Editor provides a simple interface
for manipulating elements from the MotionLayout library that
serves as the foundation for animation in Android apps.
In previous releases, creating and altering these elements
required manually editing constraints
in XML resource files.
Now, the Motion Editor can generate this XML for you,
with simple for start and end states, keyframes, transitions
and timelines.
We have updated the Layout Inspector
to provide complete, real-time insight into your app's UI.
Along with many of the same features of the existing Layout
Inspector, the Live Layout Inspector
also include a dynamic layout hierarchy,
which updates as the views on the device change.
Additionally, the property values
resolution stack helps you to investigate where a resource
property value originates in the source code
and navigate to its location by following the hyperlink
in the Properties pane.
Lastly, the 3D view assists you by showing your app's view
hierarchy at runtime with advanced 3D visualization.
To use this feature in the Live Layout Inspector window,
simply click on the layout and rotate it.
You can use the Live Layout Inspector
only when deploying your app to a device running
API 29 or higher.
You must also enable the feature by navigating
to Find, Settings, Experimental, and checking
the box next to Enable Live Layout Inspector.
Layout Validation is a visual tool
for previewing layouts in different devices
and configurations at the same time, which
can help catch potential issues in your layout.
You can access this feature by clicking
on the Layout Validation tab in the top right corner of the ID
window.
In the Layout Validation window, you
can select from four different configuration sets, including
Pixel devices, where you can preview your app on a selection
of Pixel devices.
Custom, where you can preview your app
using custom display options, such as screen orientation
or language.
Color blind, where you can preview
your app using simulations of common types of color
blindness.
And font sizes, where you can preview your app
using a variety of font sizes.
To switch between these configuration
sets, select from the drop down menu
at the top of the Layout Validation window.
Long build times are unpleasant for any developer.
But it's hard to find out which part of your
build script is making it slow.
With Android Studio 4.0 and Android Gradle plug-in 4.0,
we're introducing the Build Analyzer.
It helps you understand and diagnose issues with your
build process, such as disabled optimizations
and improperly configured tasks.
You can also specify the default setting
for these features across all modules in a project
by including one or more of the following in your projects
gradle.properties file.
If you haven't already done so, install the version 4.0
of the gradle plugin to make this work.
And build your app by selecting Build,
Make Project from the menu bar.
After that, select View Tool windows,
Build from the menu bar.
Finally, in the Build window, open the Build Analyzer window
in one of the following ways.
After Android Studio finished building your project,
click the Build Analyzer tab.
Or after Android Studio finished building your project,
click the link in the right side of the Build Output window.
Based on your feedback, the CPU Profiler UI
has been improved to provide a more intuitive workflow.
CPU recordings are now separated from the main profiler timeline
to allow for easier analysis.
For easier side by side analysis,
you can now view all thread activity in the Thread Activity
timeline, including methods, functions and events.
Events are now uniquely colored for easier differentiation
inside the system trace UI to enhance readability.
Version 4.0 of the Android Gradle plugin
allows you to enable or disable build features, such as view
binding and data binding.
You can use the features block to enable
only the features you want.
So you can improve the scalability of large products.
You can set the options for each module in the module level
build.gradle file as follows.
Android Studio now includes Android live templates
for your Kotlin classes.
For example, you can now type toast
and press the Tab key to quickly insert
a toast, same thing with a log.
For a full list of available live templates,
navigate to Editor, Live Templates,
inside your settings.
A new Android fragment wizard and new fragment templates
are now available when you navigate to Find,
New Fragment, Gallery or click New,
Create Destination in the Navigation Editor.
Android Studio now provides Smart Editor features
when you open R8 rules such as syntax highlighting, code
completion and error checking.
The editor also integrates with your Android Studio project
to provide full symbol completion
for all classes, methods, fields and also includes
quick navigation and refactoring.
Thanks to improvements in the D8 desugaring engine, Android
Studio now includes support for a number of Java 8
Language APIs without requiring a minimum API for your app.
This means you can now include standard language APIs that
were available only in recent Android
releases, such as java.util.streams
in apps that support older versions of Android.
The Android Gradle plug-in now supports
Kotlin DSL build script files.
When used with Android Studio, certain ID features,
such as the project structure dialogue
and build script quick fixes now also
supports reading and writing to Kotlin build script files.
The ability to separate annotation processing
into a dedicated task has been removed.
Instead, you should migrate to using incremental annotation
processors to improve build performance.
You can now remove the setting from your gradle properties
file, which no longer works.
Check out our quick guide on how to use incremental annotation
processors in the video description below.
In previous versions of the Android Gradle plug-in,
all dynamic feature modules could depend only
on the app's base model.
When using Android's gradle plug-in 4.0,
you can now include a feature module that depends
on another feature module.
Let's take an example.
Imagine a video module that depends
on camera modules, which depends on the base model.
When downloading the video dynamic feature,
the application will also download the camera module
automatically for you.
Here's how you can declare a module that depends on another
in your build.gradle file.
You specify inside your dependencies and implementation
of the other module project.
Additionally, you should enable the feature-on-feature
dependency feature in Android studio
to support the feature when editing the run configuration,
for example.
And you do that by clicking Help, Edit Custom VM
Options from the menu bar and including
the following properties.
Android Gradle plugin 4.0 fully removes the com.android.feature
and com.android.instantappplugins
which were deprecated since the previous release.
Developers who have not yet migrated their Instant app
to app bundles must do so now in order
to upgrade the Android Gradle plug-in to the new version,
which brings its own benefits and simplifies your app's
modular design.
When building your app using Android Gradle
plugin 4.0 and higher.
The plugin includes metadata that
describes the dependencies that are
compiled into your application.
When uploading your application, the Play Console
inspects this metadata to warn you about non-issues with SDKs
and dependencies your app uses.
And it will provide actionable feedback
to resolve those issues for you.
If you'd rather not share this information,
you can opt out by including the following code in your module's
build.gradle file.
Starting with Android Gradle plug-in 4.0,
you can now import C and C++ libraries from your app's AAR
dependencies.
Gradle will make these native libraries
available to use with your external native
build systems, such as CMake or NDK build.
Note that Gradle only makes these libraries
available to use in your build.
You must still configure your build scripts to use them.
To enable this feature, follow the configuration steps
by checking the link provided in the description below.
Enjoy Android Studio 4.0.
And remember that we are listening to your feedback
on our build tracker.
Check out early builds of Android Studio
4.1 on the Canary channel.
Don't forget to subscribe to our channel
to get notified and share the video with your friends
and colleagues.
See you soon.