[MUSIC PLAYING] ALAN VIVERETTE: Hi,
I'm Alan Viverette. And I'm a Technical Lead on the
Android Jetpack Team at Google. In this talk, I'll be covering
the latest Jetpack libraries as well as some
important changes to prerelease library features. For the uninitiated,
Android Jetpack is a suite of libraries,
tools, and guidance to help developers
follow best practices, reduce boilerplate
code, and write code that works consistently
across Android versions and devices. In short, Jetpack
makes it easier for developers to focus on
the code they care about. And since last year,
adoption of Jetpack has continued to skyrocket. In 2020, we reported
that just under half of the top 1,000 apps were
using two or more Jetpack libraries, not including
core libraries like AppCompat or Lifecycle. Today, over 3/4, 79%,
of the top 1,000 apps rely on Jetpack,
and for good reason. We've continued to improve
our existing libraries. And we've also
introduced new libraries to cover common pain points
and make development easier. Before we get to
libraries, though, I want to acknowledge
a bit of feedback that we've gotten
from the community. Jetpack releases
a lot of alphas. So we've made some
small changes. Alphas are the same. These are libraries
under active development. Features may be
incomplete, but what's there is tested and should
be highly functional. Once the library is
feature complete, it moves to beta
for stabilization. And here's the change-- there may be rare instances
where APIs change in response to critical feedback. We understand that alpha has
certain implications outside of the strict definitions
that we use for versioning. So what this means
in practice is that libraries whose features
are stable but may need more developer feedback
will reach beta sooner with the same level of
functional stability the developers
expect from a beta. While it's nice to have
more flexibility in beta, there occasionally features
that just need more time. Jetpack has introduced
new metadata and tooling to isolate individual
features, meaning developers will see libraries reach
stable much sooner. In practice, feature
isolation looks like this. APIs are annotated as part of
an experimental feature set. And then any calls to it
require explicit opt-in. For folks using
Kotlin, this might seem familiar-- the
"requires opt-in" annotation. Jetpack has introduced
an equivalent set of Java
annotations as well as a lint check that enforces
the same opt-in semantics as the Kotlin compiler. So opting in means that
the developer understands that the API is
alpha quality, and it may change in the future. And when the feature
is stabilized, the annotation can be removed. We use this
extensively in Jetpack. But the annotation-bundled
lint check are available for anyone to
use in their apps or libraries. One of the places where
you may see experimental is CameraX, where
it's being used to ensure that the library
can move to stable as devices continue to evolve. The CameraX library provides
a unified API surface for access and
camera functionality across OS versions, including
device-specific compatibility fixes and workarounds. Some of the latest
improvements to the library address common feature
requests, including support for adjusting exposure
compensation and access to more detailed information
about camera state and features. Additionally, camera
settings like FPS range may now be changed
via camera2 inter-op while the camera is running. The library also brings support
for the latest device and OS features, including high
dynamic range preview, zoom ratio controls, and
support for Android's do-not-disturb mode. Perhaps most importantly,
though, the library has continued to
address performance, resulting in faster
image capture and faster initialization, especially
on older devices. To support more robust
application design, the most recent alpha version
of the CameraX library has split CameraView
into CameraController, which provides interaction
with camera features like zoom and focus and
preview view, which is responsible for
rendering the camera preview and integrating with
the Android view system. Here, we're setting a
preview and taking a photo. But CameraController
provides much more, including image analysis and
additional capture options. For developers interested
in full-text search, the new AppSearch library
provides high performance and feature-rich
search functionality. AppSearch provides
everything you'd expect from full-text search. And in comparison to SQL,
the AppSearch library makes it easy to
perform fuzzy matching, handle synonyms and
spelling correction, support multiple
languages, and much more. AppSearch simplifies
data representation by including schemas
for common object types based on schemas.org
and on Android S and later. It allows developers
to surface their data in device-wide search. For developers that just
want to store basic data, the DataStore library
provides a robust approach that addresses the shortcomings
of SharedPreferences while maintaining a simple,
highly usable API service. As a modern replacement
for SharedPreferences, DataStore brings support
for best practices like Kotlin coroutines
with Flow and RxJava. DataStore also provides multiple
ways to define a data model-- as a loosely typed
key-value store that's similar to the
old SharedPreferences model, a proto DataStore,
which stores strongly typed objects using
protocol buffers, or whatever fits the use case. So why should
developers migrate? Well, while SharedPreferences
works OK for smaller apps, DataStore can provide strong
guarantees around type safety, asynchronous operations,
and error handling, as well as a number of useful
features like data migration. Migrating from
SharedPreferences to a basic key-value preferences
DataStore is simple. Here, we're creating a
SharedPreferences migration object and passing in the
name of our SharedPreferences and then using it to
create our DataStore. That's it. Now we can access
our preferences using the new DataStore model. And for developers who
are storing preferences, wouldn't it be nice to
provide safety guarantees for your security-critical
preferences? The Security Crypto
library does just that, providing an easy way to
encrypt files and preferences. The library has
recently launched a stable with
DataStore integration planned for a future version. To encrypt
SharedPreferences, simply create an encrypted
SharedPreference object with the appropriate
key and scheme. And then use it like you would
a standard SharedPreferences object. Also moving to 1.0
stable, we have Hilt, Jetpack's recommended
dependency injection solution built on top of Dagger. As part of the
transition to stable, Hilt's ViewModel support has
moved up into the core Hilt Android APIs. And SavedStateHandle has been
added as a default dependency available in the component. A developer can obtain an
annotated Hilt ViewModel from an Android entry point,
like an activity or a fragment, or obtain a ViewModel scoped
to the entry point's navigation back stack. Hilt has also made improvements
to WorkManager integration, using AssistedInject. With this change,
developers no longer need to create their
own worker factory and pass in
dependencies manually. They can now obtain
the dependencies from Hilt's dependency
injection graph and remove quite a bit
of boilerplate code. Additionally, Hilt
has made improvements to testing with the new
TestInstallIn annotation. This annotation allows you
to uninstall and replace modules in tests with
build performance improvements over the existing
UninstallModules annotation. Here, all tests
that would normally be injected with
RepositoryModule will instead receive the
FakeRepository module. The WorkManager library, which
is Android's recommended way to schedule deferrable,
asynchronous tasks that run even if the app exits
or the device restarts, has made improvements
to reliability, with task reconciliation
ensuring all tasks are executed and a variety of workarounds for
specific Android OS versions. The latest versions
of WorkManager feature improved support
for multi-process apps, including performance benefits
from unifying work request scheduling into a single process
and limiting database growth when scheduling many requests. Version 2.7, which is
targeted to the Android S SDK, provides additional support for
the platform's new foreground restrictions. See the effect of background
tasks on Android Talk for more information on using
WorkManager on Android S. We're also very pleased to
announce that the WorkManager Inspector is now available
in Android Studio Arctic Fox. This tool allows developers
to easily view and debug WorkManager jobs when using the
latest versions of the library. The Inspector tool can be opened
from Android Studio's Tool Windows menu. And from there,
the tool displays the active workers in
an app live on device. Developers can perform
operations on workers, including removing them
from the queue or stopping execution, which can
help investigate issues with scheduled jobs. The tool can also provide
more detailed information about an individual worker,
including how it's executed, details of its worker chain,
and execution results. Room, Jetpack's recommended
data persistence layer, which provides
increased usability and safety over the platform,
has also reached stable. The latest version
of the library brings experimental support
for Kotlin Symbol Processing, which, in our benchmarks
of Kotlin code, showed a 200% speed
improvement over kapt, as well as built-in support
for enums and RxJava3. Room has also introduced
a QueryCallback class, which provides a callback when
SQLite statements are executed to simplify tasks like logging. As well as the new
ProvidedTypeConverter annotation, which
allows more flexibility when creating type converters. Previously,
developers had to rely on static methods,
no-arg constructors, and build time verification. With this annotation, however,
the type conversion object can be constructed at
runtime with whatever additional information
it needs, and Room will verify its availability
when the database is built. On the user interface
side of Jetpack, ConstraintLayout, a flexible
system for designing layouts, has reached 2.0 stable. Along with it, MotionLayout
is now stable and ready to provide rich animation
and state management. MotionLayout is based
on ConstraintLayout and provides no-code-necessary
motion animation, including support for foldable
devices, image filters, and motion effects. And Studio's Motion
Editor gives developers an interactive visual tool
for designing animations. Check out the "What's
New in Design Tools" talk to learn more
about using Motion Editor with MotionLayout. Over the past year,
the Fragment library has undergone a major
effort to clean up its internal implementation and
reduce undocumented behavior, making it easier for
developers to follow best practices in their apps
and write reliable tests. This lays the groundwork
for future improvements to the library. And it may require some work to
accommodate strict enforcement of API contracts. In practice, this
means that developers should pay careful
attention to their tests after updating the library. The Fragment release notes
call out specific cases to watch out for. Recent releases have also added
ActivityResult integration, making it possible to
register for ActivityResults from a fragment. Fragment has also introduced
a new FragmentOnAttachListener interface to replace the less
flexible onAttachFragment. Existing code that overrides
the method in FragmentActivity will still work. But we've deprecated
onAttachFragment to help prevent new code from
accidentally adopting a less flexible approach. The latest alpha
of Fragment also integrates with the Navigation
library, Jetpack's framework for moving between
destinations in an app to provide support for
multiple back stacks and simplify cases
where destinations sit at the same depth, such
as a bottom navigation bar. For developers who'd like
to integrate more closely with Google Assistant, the
Google Shortcuts library provides a way to expose actions
to Assistant and other Google services through the
existing ShortcutInfo class. Developers can send
up to 15 shortcuts at a time through
the ShortcutManager to be shown on Google
Assistant, among other services, making them available for
voice and other interactions. Here, we've defined a shortcut
with an intent and capability binding. This binding provides
semantically meaningful information that will help
Google services figure out the best way to
surface it to users. And for any app that might
need to display emoji, which, at this point, is basically
any app with a text input or network-backed
data, the EmojiCompat library has introduced a
new major version with a smaller footprint. Any app that's using
AppCompat 1.4 or later will automatically
pull in EmojiCompat, giving it the ability to
dynamically load new emoji and stay current with
the latest Unicode spec. Apps that aren't using AppCompat
can receive the same benefits by pulling in the
EmojiCompat TextView class and using it in place of
the platform TextView. Paging, which helps developers
load portions of data to improve performance
and resource consumption, also joins the
stable release club with its 3.0 major version. This release features a
complete rewrite in Kotlin with first-class support
for coroutines and Flow, asynchronous loading with
RxJava and Guava primitives, and overall improvements to
the presentation and repository layers. The 3.0 release is a
substantial improvement in usability over Paging
2.0, and the rewrite was planned with partial
and staged migrations in mind so that
developers can transition on their own schedule. For developers interested
in understanding their app's performance, the
Macrobenchmark library extends Jetpack's
benchmarking coverage to app startup and
integrated behaviors like scrolling performance. The library can be used
remotely to track metrics in continuous
integration testing or locally with profile results
viewable from Android Studio. Check out the "Measuring
Jank and Startup with Macrobenchmark"
talk to learn more about using the library. We're also pleased
to announce that many of the libraries I've
talked about today, as well as others developers
are already using, have introduced
features specifically for integration with Jetpack's
new UI toolkit, Compose. Make sure to check out
the "Jetpack Compose" talk to learn more about
the new UI tool kit and watch the "Using Jetpack
Libraries and Compose" talk to learn how
to use the latest versions of popular
Jetpack libraries, including Navigation,
ConstraintLayout, and more with Compose. Jetpack is also making it
easier to write UI for new form factors, including foldables,
large-screen devices, and Wear devices. Check out the "What's
New in Foldables" and "Now is the Time" talks
to learn more about developing for these form factors. We've covered a lot of
libraries in this talk, but there are quite
a few more new and updated libraries
that developers might want to check out. Full details for
every Jetpack library, including release notes,
Maven coordinates, and API reference
docs can be found on
developers.android.com/jetpack. Tip-of-tree library snapshots
are available at androidx.dev. Thanks for watching,
and have a nice day. [MUSIC PLAYING]