YACINE REZGUI: Android Studio version 4.1
is now available for download on the stable channel.
This new version of Android Studio
adds new features, a database inspector, Dagger navigation
support, a native memory profiler, the ability
to use the emulator directly inside Android Studio,
but also importing TensorFlow Lite models, improvements
for apply changes, and more.
This version includes updates from IntelliJ 2020.1,
such as a new Commit Tool window, which
allows you to take advantage of the editor area
to visualize this more comfortably,
a new Interactively Rebase dialog
where you can rework the Get History tree easily, switch
between branches directly from the bottom bar,
store Run Configurations files to be able to share them
or import them in other projects, Quick Type definition
popup without switching focus from your code,
and Javadocs rendering within the editor.
We've also updated the locations of user configuration
directories to the following paths.
These new directory locations are
consistent with recent updates to IntelliJ IDEA.
Storing data in an SQLite database
is the common way to save structured information
for Android applications, and Jetpack Room
facilitates interactions with it,
but debugging and inspecting data inside a database
is not always easy.
With a new Database Inspector, you can check its values,
as well as query and modify them.
To get started, deploy your app to a device or emulator running
API level 26 or higher and select View Tool Windows
Database Inspector from the menu bar.
If your app makes updates to its database
and you want to automatically see
those updates in the Inspector window,
check the box next to Live Updates.
We also added an integration for Jetpack Room.
Android Studio now provides gutter actions
to help you quickly run queries you defined using the add query
annotations to avoid writing them manually in the Inspector.
Following the principles of dependency injection
will help you better organize your application architecture.
We created the Dagger library to help you
with dependency injection, and more recently, the help
library, to make it even easier.
For projects using these libraries,
Android Studio now provides gutter actions
that help you navigate between your Dagger annotated
dependencies and the parts of your code where they are used.
You can also search those dependencies
and their consumers, when invoking find use agents.
The Android emulator can now run directly in Android Studio
to avoid switching between different windows
and navigate quickly between the emulator and the editor area
using hotkeys.
Since we're extending capabilities
to this feature over time, this is not turned on by default,
and you need to click on the emulator tool window
to enable it.
We have invested heavily on getting faster deploy speeds
with Apply Changes.
After an initial deploy, subsequent deploys
to Android 11 devices are now significantly faster.
With our simple app, Sunflower, Apply
Changes to 250 milliseconds in average compared to 2 seconds
and 1/2 previously.
In addition, you can now add methods
without reinstalling your app, by clicking either Apply Code
Changes, or Apply Changes and Restart Activity.
To learn more about the differences between those two
actions, you can watch this video
on how to use Apply Changes.
Profiling your application is crucial to find out
how to optimize it and use less resources.
As the profiling process is consuming
a lot of computer resources, we are adding the possibility
to open the profiler in a standalone mode
with a separated window from the primary Android Studio window.
Using assertions in the Java code
has been a common way to debug an application,
but they were having no effect when
run on an Android device or emulator,
as the Android runtime doesn't support assertions at runtime.
When using Android Gradle plugin 4.1
and deploying a debug version of your app,
the built-in compiler, D8, rewrites your code
to enable assertions at compile time,
so you always have the assertions checks active.
This feature currently supports only apps written in the Java
programming language, but support for Kotlin
is coming soon.
Android Studio now makes it easy to use machine learning
in your app, by directly importing TensorFlow Lite
models and using them in your project.
It will generate a binding class,
so you can run your model with less code and better type
safety.
To get the most from this new function,
use models that have the new TensorFlow Lite metadata.
We currently support models that use numbers and images
as its inputs or outputs.
Discovers come in machine learning
model types, such as image classifications and style
transfer.
For older models that do not have this metadata,
or models that require other types of input/output,
such as strings, the binding class
will default down to TensorBuffer rather than
Android-friendly types.
This feature is still under development,
so please provide feedback or report bugs on our issue track.
Material Design has been the recommended way
to design applications on Android.
And now Android Studio templates in the Create New Product
dialog use Material Design Components,
and conform to updated guidance for themes and styles,
supporting dark themes by default,
and using a more maintainable structure.
You can read this blog post to learn
how to migrate to material components for Android.
The Design Tools Suite in Android Studio
is a powerful collection of tools
that aims to support developers in designing, prototyping
and debugging the application UI.
In Android Studio 4.1, we've improved the experience
with these tools, including Design Time Attributes Toggle,
to allow users to easily turn on and off tools visibility
attributes and absolute positioning.
A visibility control on component tree,
providing a quick way to easily set
Show, Hide, Gone visibility with both tools and Android
namespace.
Visualizers and sliders to help with 3D rotation of use
within the Attributes panel.
And more updates for the navigation editor
and the Motion Editor.
Check out this blog post to read more about these updates.
This release of Android Studio includes a lot of changes
beneficial to NDK developers.
The first one is the Native Memory Profiler
for apps deployed to physical devices running
Android 10 and later.
With a sample size of 32 bytes, the Native Memory Profiler
tracks allocation and deallocation of objects,
as well as their size in bytes in native code
for a specific period of time.
To initiate a recording, click Record Native
Allocations at the top of the Memory Profiler window.
When a crash occurs, or when an app
becomes unresponsive in native code,
this system produces a stack trace,
which is a snapshot of the sequence
of nested functions called in your program
up to the moment it crashed.
These snapshots can help you to identify and fix
any problems in the source code, but they must first
be attached with symbols to translate the generated machine
code back into human readable function names.
If your app or game is developed using native code like C++,
you can now upload debug symbol files to the Play Console
for each version of your app.
The Play Console uses these symbols to symbolicate your app
stack traces, making it easier to analyze
crashes or responsive events.
Before you can upload debug symbol files,
you must be using Android Gradle plugin version 5.1 or higher.
Check out the documentation to follow the instruction
to enable this feature.
Android Gradle plugin 4.0 added the ability
to import prefab packages in AAR dependencies.
With Android Gradle plugin 4.1, you
can now publish libraries from your external native
build in an AAR for an Android library project.
To publish your native libraries,
add the following code to your library build Gradle file.
In this example, the my library and my other library,
libraries from either your NDK build or CMake
external native build will be packaged in the AAR produced
by your build, and each will export the headers
from the specified directory to their dependents.
You can now set the path to your local NDK installation,
using the android.ndk path property in your module's build
Gradle file.
If you use this property together with the Android NDK
version property, then this path must contain an NDK directory
with the same version as android.ndk version.
Enjoy Android Studio 4.1, and remember
that we are listening to your feedback on our bug tracker.
Check out early builds of Android Studio
4.2 on the canary channel.
Don't forget to subscribe to our YouTube channel
to get notified for new content, and share
this video with your friends and colleagues.
See you soon.