What’s new in Jetpack
Android Jetpack is a suite of libraries aimed at helping you write high-quality apps easily, supporting older versions of the Android OS. Now, two years after the launch of Jetpack, we’ve seen tremendous adoption by apps, from large developer teams to those just getting started. And that’s just the beginning: today, we’re launching new libraries, along with major updates to existing ones, that we’ve been working on over the past year. Here’s a round up of the latest updates in Jetpack — an extended version of our What’s new in Jetpack talk!
New in Alpha
Hilt — Jetpack’s recommended library for Dependency Injection
Hilt is a new Android library which simplifies dependency injection (DI) in your application. Hilt lets you focus on just the important parts of defining and injecting bindings without worrying about managing all of the DI setup and wiring.
Built on top of Dagger, Hilt benefits from it’s compile-time correctness, improved runtime performance, and scalability. Hilt adds integration with Jetpack libraries and Android framework classes. For example, to inject parameters of a ViewModel
you can now annotate the ViewModel
constructor with @ViewModelInject
and then annotate the Fragment
with @AndroidEntryPoint
:
Find out more about Hilt and discover more links to related resources in our launch blog post.
Paging 3 — load and display data incrementally
Paging is a library that helps you load and display small chunks of data incrementally. Today we’re releasing Paging 3 — a complete rewrite of the library using Kotlin coroutines. This new release adds highly requested features like separators, headers, footers and list transformations and APIs for observing list loading state and methods for retry and refresh.
For example, with Paging 3, the data source can be defined by extending the PagingSource
class and implementing the load
suspend
function, where you can directly call other suspend functions:
For more information about Paging 3, check out the documentation and our codelab.
App Startup — initialize components at application startup
The App Startup library provides a straightforward, performant way to initialize components at application startup. Instead of defining separate content providers for each component you need to initialize, App Startup allows you to define component initializers that share a single content provider. This can significantly improve app startup time.
Here’s how App Startup can be used to improve the initialization time of WorkManager, a library that uses a ContentProvider
under the hood, after disabling the WorkManager’s own ContentProvider
:
For more information on App Startup, check out the official documentation.
Auto-fill IME integrations
Android 11 introduces platform APIs for keyboards to display autofill suggestions from apps such as password managers. Jetpack’s Autofill API makes it easier for keyboards and autofill services to take advantage of this new feature via its InlineSuggestionUi
class. Autofill services can use this class to create compatible suggestions; keyboards can use it to customize the style of the suggestions.
Easier animations with core-animation and SeekableAnimatedVectorDrawable
To make implementing and testing animations easier, we’ve added two new libraries: androidx.core:core-animation
and androidx.core:core-animation-testing
. We’ve also introduced a new API SeekableAnimatedVectorDrawable
as part of androidx.vectordrawable
library.
core-animation
backports all the features added to the Animator
API since Ice Cream Sandwich, such as pause/resume and seek.
SeekableAnimatedVectorDrawable
, based on core-animation, is a new, seekable alternative to AnimatedVectorDrawable
(AVD). It uses the same format as AVD and adds the ability to seek, pause, and resume playback. Seekable AVDs cannot use the render thread so should only be preferred to AVD when the new class’s additional features are required.
Debug your database with Database Inspector in Android Studio
Debugging issues with your database is now easier in Android Studio 4.1 Beta with the new Database Inspector. This tool enables you to inspect, query, and modify SQLite databases in your running app. Whether you’re using Room or SQLite directly, you can start debugging your databases by selecting View > Tool Windows > Database Inspector from the menu bar. Find out more about the tool and how to use it in this blog post.
WindowManager — better support for device form factors
The WindowManager library is a new addition to Android Jetpack that aims to help application developers support new form factors like foldables, hinged screens, and more. It provides a common API surface for different WindowManager features on both old and new platform versions.
The initial release provides support for different types of foldable devices already on and coming to the market, so that application developers can target entire categories of hardware configurations. Check out the overview in this blog post and the samples to learn more.
MotionLayout — build fluid and interactive animations for Android
The MotionLayout API extends the rich capabilities of ConstraintLayout
to help Android developers manage complex motion and widget animation in their apps. With MotionLayout
you can model your animations as transitions between ConstraintSets
and easily integrate animations with common views like RecyclerView
and ViewPager
. Android Studio 4.0 also includes the Motion Editor, a graphical tool for creating and previewing animations that use MotionLayout
.
Updates to existing libraries
Navigation
Navigation 2.3 adds support for dynamic feature modules which allow you to download pieces of your application as the user needs it, significantly reducing the initial download size of your app. Now, you can navigate to these modules as if they are part of the base APK. Along with allowing query parameters, deep links now support custom actions and mime types.
A new API for returning a result, allows you to query any back stack entry and set the result on its SavedStateHandle
. The new TestNavHostController
enables you to access the Navigation back stack and set the current destination in tests.
WorkManager
The latest releases of WorkManager, add support for long-running or important work that should be kept alive by the operating system using foreground services.
To make it easier to diagnose issues with your WorkManager tasks, we added a new diagnostics API that allows you to peek into the internal state of WorkManager
and dump its state into logcat:
To help you to avoid common mistakes when using WorkManager, we’ve also added Lint rules to flag them. Other API updates include: support for setting and observing intermediate progress for workers; improvements to the query API for current workers; and improvements to the in-process scheduler used to run your workers.
Benchmark
The new alpha release of the Benchmark library integrates with CPU profiling so you can profile your benchmarks and then view the method or sampled traces right in Android Studio. We’ve also added support for memory allocation tracking, so that you can optimize the time spent allocating and reduce the load on garbage collection.
Permissions
To make it easier to work with permissions we introduced the new ActivityResult
APIs. These APIs simplify requesting permissions by replacing requestPermissions
with the RequestPermission
contract, but also provide type-safe contracts for common intents, like taking a picture or prompting the user to open a document.
Games SDK
The Android Games SDK, launched earlier this year, is now also part of Jetpack and available on the Google Maven Repository. The SDK currently offers a Frame Pacing API and Android Performance Tuner. Find out more about the Games SDK from the official documentation.
CameraX
There’s a lot of variation in cameras across Android devices; CameraX runs on 90% of them. Since CameraX reached beta last February, we’ve been focusing on reliability to ensure the best behavior of the API across a large range of devices. Our CameraX test lab runs our automated test suite on device types representing over 400M active devices in use.
The latest version of CameraX brings improvements to the PreviewView
widget. It now handles interactions with your application lifecycle and view pagers reliably. It is also optimized to transparently use SurfaceView
under the hood on devices that would benefit from its performance enhancements. This results in less buffering and better power efficiency.
Check out the extensive CameraX documentation and samples to learn more about the APIs.
Security
Jetpack’s Security library provides safe and easy to use file-based crypto abstractions like EncryptedFile
and EncryptedSharedPreferences
. Jetpack Security takes advantage of Android’s Keystore, which provides hardware-backed storage and operational safety. Jetpack Security is now at Release Candidate 2 for Marshmallow+, and 1.1.0 alpha for Lollipop+ support.
AppCompat
AppCompat provides backports for a wide variety of UI elements and platform features, from the Material theme, to widgets like the Toolbar
, to dark theme. In the latest releases, we’ve added Lint rules that allow you to better understand which attributes come from AppCompat and which from the framework, and ensure you use the right one. We’ve also made substantial stability improvements to AppCompat’s implementation of dark theme.
Webkit
Jetpack’s Webkit library adds a new API in 1.2.0 release to force dark mode for its content. When this API is enabled, WebView will render sites in dark theme where supported. Where websites don’t support dark theme, the API will invert certain colors.
Jetpack Compose — Android’s new UI toolkit
Jetpack Compose, Android’s new, modern UI toolkit, is now in Developer Preview 2. This release adds many new features: View interoperability, more Material UI components, dark theme support, new UI testing and animation APIs, initial support for ConstraintLayout
, improvements to state management, integrations with observable streams and RTL support. Android Studio previews can now be interactive, and there have been many compiler improvements.
Find out more about all the updates from the What’s new in Compose talk, and then try it out and give us feedback.
This was a quick tour of all the Jetpack updates of the last few months. With 90+ libraries available, we know that it can be hard to find the one you need. To fix this, we redesigned the Jetpack webpage and added, among others, a handy API picker to quickly go from the problem you have to the Jetpack library that can solve it.
To find out more about the Jetpack libraries, stay tuned for new videos, blog posts, and codelabs coming out in the Jetpack week (week of July 20th) of the 11 Weeks of Android.