The latest version of Android Studio, dubbed Dolphin, improves Jetpack Compose screen previews, extends Wear OS support, and introduces Gradle Managed Virtual Devices to simplify test automation.
The Jetpack Compose screen preview gets three new features: multi-view annotations, an animation inspector, and recompose count. Multipreview annotations aim to reduce boilerplate code with preview definitions that specify devices to generate previews for, fonts and themes to use, and more. The annotations can then be reused to avoid copying and pasting the definitions themselves, as developers had to do until now. The following snippet shows how you can set a FontScalePreviews
annotation and use it in a composable preview:
@Preview(
name = "small font",
group = "font scales",
fontScale = 0.5f
)
@Preview(
name = "large font",
group = "font scales",
fontScale = 1.5f
)
annotation class FontScalePreviews
...
@FontScalePreviews
@Composable
fun HelloWorldPreview() {
Text("Hello World")
}
The Animation Preview Inspector helps preview and refine animations by letting you freeze an animation or run it frame by frame.
The composition recomposition count, available in the Layout Inspector, indicates how often a view is recomposed, that is, rendered. This can help identify cases where redialing too often can negatively impact performance.
Gradle Managed Virtual Devices is a new feature that aims to make it easier to manage and configure emulators used for testing. Instead of having to manually perform all the steps required to provision an emulator for testing, you can now describe the virtual devices you want in your build.gradle
case. The tool will then download the corresponding SDK, if necessary, provision and configure the emulator, and launch your tests. Here’s how you can use this feature indoors gradle.build
:
android {
managedDevices {
devices {
pixel2api30 (com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Pixel 2"
apiLevel = 30
systemImageSource = "google-atd"
}
...
}
}
}
As mentioned, Wear OS support is also improved in Android Studio Dolphin. This includes a new Wear OS emulator pairing wizard that helps manage and pair multiple Wear OS devices; Improved emulation toolbar that better aligns with physical devices and emulates palm gestures and tilt; and better support for launching a Wear OS app in the exact state you expect, directly from the IDE.
Finally, Android Studio Dolphin is updating its compiler toolchain to IntelliJ 2021.3, which includes a number of improvements including better Kotlin debugging, improved suggestions, and remote coding support.
Android Studio Dolphin can be downloaded from the Google Android website or installed directly from a previous version.