TAKESHI HAGIKURA: Android Studio Dolphin, also known
as version 2021.3.1, is now stable and available
for download.
This version brings a lot of changes,
including tooling improvements in Jetpack Compose,
stable support for Gradle Managed Devices,
improved support for OS, and more.
Let's see all of this in detail.
First, let's look at the improvements
to Jetpack Compose tooling.
In an [INAUDIBLE] UI model, you call a setter
to change its internal state.
In Compose, the framework calls the composer function
with new data when the values used by the composer tool
are changed, which is called recomposition.
To easily understand when your UI recomposes,
the Layout Inspector now allows you to see the recomposition
when the skip counts to inspect potential problem
or issues in your app.
Let's take a look at the example code.
We have two buttons and its clicked accounts are shown.
Run the application and open the Layout Inspector to make sure
Show Recomposition Count is ticked.
As you clicks the first button, you
can see the recomposition count for the first button
is increased.
It is also important to make sure recomposition count
for the second button isn't increased
because the recomposition should only
happen for components whose dependent values are changed.
To enable recomposition counts, make
sure you use at least version 1.2.1
of the Compose UI tooling library.
Want to learn more about the Compose performance,
check out the document about what is recomposition
under this Google I/O video.
We introduced Animation Preview in Android Studio Chipmunk,
where you can preview the Compose Animation,
but it was limited to a single animation.
With Android Studio Dolphin, it's
possible to see all the animations at once
and the coordinates of them.
To begin, click on the Start Animation Preview
button in the Compose Preview window.
Now you can see our Animations tab
where you can play all the animations, change the speed,
and skip to a specific time.
The Animation Preview window can also
visualize the animation curves to make
sure the animation values are choreographed properly.
Additionally, if you are using Compose UI tooling
version 1.2 or higher, you can freeze animations
by expanding it and clicking the freeze icon for the selected
animation to only inspect the specific ones.
For now, only the updateTransition
and AnimatedVisibility APIs are supported,
with more coming in future versions of Android Studio.
Keep in mind that Start Animation Preview
button will only be shown when those animations are detected.
Check out a collection of Compose Animation samples,
where you can play with various APIs.
The last improvement in the Compose tooling
is multipreview.
When you want to preview your Compose
work in a variety of configurations,
like both dark and light mode or different device sizes,
you need to repeat those definitions
for every single composable.
Rather than writing separate Compose previews
for each of these configurations,
Android Studio Dolphin introduces multipreview,
which allows you to create multiple previews
for each composable.
Let's take a look at the example in Jet [? News. ?] Here
you can see an annotation class is different font sizes.
And here's one with different device types.
And here's another annotation class
that combines both the fonts and the devices.
When attached to a composable, the preview window
renders multiple previews based on the preview configurations.
Note that combining multiple annotations doesn't
mean all the different combinations of options
are shown.
Instead, each annotation renders only its own variants.
In this case, two previews for light and the dark themes,
two previews for font scales, and three previews for device
configurations are shown.
For more details, take a look at the documentation.
Next up, testing.
Gradle Managed Devices and Automated Testing Devices
are now stable.
Gradle Managed Devices allows you
to define a set of virtual devices
in the build.gradle file that are fully managed
by the Android Gradle Plugin.
This means that the creation, deployment,
and the teardown of the devices are
handled by AGP automatically when
running instrumented tests.
Let's take a look at an example of a device
definition in the app module of the build.gradle file.
Here we give the virtual device a name.
Then we tell the Android Gradle Plugin
to use the Pixel 3 device and to set the apiLevel to 30.
You can use the same device profiles
and the API levels that are available to you
from Android Studio.
Finally, we want this device to come up with Google Play
Store under APIs.
So we set the source of this image as google.
Alternatively, you can set the source of the image
as aosp if you don't need Google Play Store under APIs.
To run test with Gradle Managed Devices,
run the AndroidTest task with the device-name
and the build-variant.
For example, if you want to run the test
against the virtual device we configured previously
using the debug version of the build, run the following
command.
Note that if you used this feature before by passing
the experimental flag, you can now remove the flag
because the feature is stable.
Android Gradle Plugin does all the heavy lifting for you,
from downloading the system images it needs,
running the tests on the device, returning more results,
to shutting down the device after the tests are finished.
Another testing feature that has become stable
is the Automated Test Devices.
An Automated Test Device is a special type of GMD image
which removes preinstalled apps that are typically not
useful for testing your app, disables certain background
services, and disables hardware rendering
to use fewer system resources.
To use an Automated Testing Device,
first make sure you update the Android Emulator to the latest
available version.
Then add the atd suffix in the Gradle Managed Device's
configuration.
Note that there are also Google ATD devices
available with Google Services.
But if you don't need them, aosp-atd is even lighter.
You can now test from the command line,
just like you would using other Gradle Managed Devices.
Android Studio Dolphin also introduces several improvements
for Wear OS.
In the past, it was cumbersome to pair Wear OS emulator
with a phone device because you needed
to forward the emulator's communication port
using adb command.
The new Wear OS Emulator Pairing Assistant,
added in the Device Manager, allows
you to connect a Wear OS emulator to a physical
or virtual device more easily.
To use the Pairing Assistant, click the Overflow menu
at the right of the Wear OS emulator
from the Device Manager and the select Pair Wearable.
Then select the companion device from the list.
Note that the companion device must
be running Android 11 or higher, and it
has to have the Google Play Store installed.
Once the connection is established,
you can see the linked icons on both the Wear OS emulator
and the companion device.
Now you are able to configure the behavior of the Wear OS
emulator using the companion app on the phone device.
Moving on to the next improvement,
new run configurations have been added
to quickly run Android debug services specific to Wear
OS, such as watch faces, tiles, and the complications.
To begin, click the gutter icon next to the declaration
of the surface.
For example, here you can see a declaration for WatchFace.
It will create a run configuration
if it hasn't been created, and you can now
run or debug the watch face, just like a normal Android
application.
Alternatively, you can create a new configuration
by navigating to Run and then click Edit Configurations.
You can now choose configurations
for watch faces, tiles, and complications,
or edit a existing configuration you have created.
The last improvement for Wear OS is the updated toolbar
for the Wear OS emulator.
Wear OS emulators with API level 30 or higher
now have buttons that resemble and simulate
the physical buttons on Wear devices.
The new buttons include two main buttons
that act as the physical button on the watch,
and the palm button and the tilt button that simulate activating
gestures on the watch.
Moving on to other updates, Logcat
has been updated to make it easier to parse, query,
and track logs.
Logcat now formats logs to make it easier
to scan useful information, such as tags and messages,
and identify different types of logs, such as warnings
and errors.
You can create multiple tabs within Logcat
so that you can easily switch between different devices
or queries.
Additionally, you can split the build within a tab
by right-clicking in the log view
and selecting either split right or split down.
Each split allows you to set its own device connection, view
options, and query.
You can also quickly switch between different view modes--
standard, contact, and custom--
by clicking the configure Logcat formatting options button.
Each view mode provides different default settings
for the level of detail shown, such as timestamps, times,
and the process IDs.
You can customize each of these default view modes
to suit your preferences by selecting Modify View.
In the previous version of Logcat,
you had the option to either use a sorting search
or create a new filter by populating various fields using
the Logcat UI.
But it was difficult to search, set up queries, and share
queries.
To address these issues, the new Logcat panel
introduces key value-based searches
right from the main query field to simplify the querying
experience.
This new system enables you to write
queries which you can access later on or even share
with other team members.
Let's see some example queries.
package:mine filters the logs for the process IDs
for the local app.
You can filter the logs by specific tag values,
such as tag:tagname, or specific level of logs such as info,
warn, or error.
You can also exclude a specific value
by prefixing the key with dash.
Finally, you still have the option
to use a regular expression in the query field
by placing a tilde after the key.
It's good to know that as you type in the query field,
Android Studio suggests the keys or values based on what you
have typed in the query field.
By pressing a Control plus Space.
You can explicitly see the suggested values
from Android Studio.
That's it.
I hope you enjoy the new features and improvements
in Android Studio Dolphin.
Please help us improve the future version of Android
Studio by submitting your feedback on our issue tracker
linked from the description.
Remember to subscribe to our channel
to not miss the future updates.
See you next time.