HomeAndroidAndroid Builders Weblog: Google I/O 2023: What's new in Jetpack

Android Builders Weblog: Google I/O 2023: What’s new in Jetpack



Posted by Amanda Alexander, Product Supervisor, Android

Android Jetpack is a key pillar of Fashionable Android Growth. It’s a suite of over 100 libraries, instruments and steerage to assist builders comply with finest practices, cut back boilerplate code, and write code that works constantly throughout Android variations and units with the intention to concentrate on constructing distinctive options in your app. The vast majority of apps on Google Play depend on Jetpack, actually over 90% of the highest 1000 apps use Jetpack.

Beneath we’ll cowl highlights of current updates in three main areas of Jetpack:

  • Structure Libraries and Steerage
  • Efficiency Optimization of Purposes
  • Person Interface Libraries and Steerage

After which conclude with some extra key updates.

1. Structure Libraries and Steerage

App structure libraries and parts make sure that apps are strong, testable, and maintainable.

Knowledge Persistence

Most purposes have to persist native state – whether or not it’s caching outcomes, managing native lists of person enter information, or powering information returned within the UI. Room is the beneficial information persistence layer which supplies an abstraction layer over SQLite, permitting for elevated usability and security over the platform.

In Room, now we have added many brand-new options, such because the Upsert operation, which makes an attempt to insert an entity when there isn’t a uniqueness battle or replace the entity if there’s a battle, and assist for utilizing Kotlin worth courses for KSP. These new options can be found in Room 2.6-alpha with all library sources written in Kotlin and helps each the Java programming language and Kotlin code era.

Managing duties with WorkManager

The WorkManager library makes it simple to schedule deferrable, asynchronous duties that have to be run reliably as an illustration importing backups or analytics. These APIs allow you to create a job and hand it off to WorkManager to run when the work constraints are met.

Now, WorkManager means that you can replace a WorkRequest after you might have already enqueued it. That is usually obligatory in bigger apps that steadily change constraints or have to replace their staff on the fly. As of WorkManager 2.8.0, the updateWork() API is the technique of doing this with out having to undergo the method of manually canceling and enqueuing a brand new WorkRequest. This enormously simplifies the event course of.

DataStore

The DataStore library is a strong information storage resolution that addresses points with SharedPreferences and supplies a contemporary coroutines primarily based API.

In DataStore 1.1 alpha we added a extensively requested characteristic: multi-process assist which lets you entry the DataStore from a number of processes whereas offering information consistency ensures between them. Further options embrace a brand new storage interface that permits the underlying storage mechanism for Datastore to be switched out (now we have supplied implementations for java.io and okio), and now we have additionally added assist for Kotlin Multiplatform.

Lifecycle administration

Lifecycle-aware parts carry out actions in response to a change within the lifecycle standing of one other element, resembling actions and fragments. These parts assist you produce better-organized, and sometimes lighter-weight code, that’s simpler to keep up.

We launched a steady model of Lifecycle 2.6.0 that features extra Compose integration. We added a brand new extension technique on Stream, collectAsStateWithLifecycle(), that collects from flows and represents its newest worth as Compose State in a lifecycle-aware method. Moreover, numerous courses are transformed to Kotlin and nonetheless retain their binary compatibility with earlier variations.

Predictive Again Gesture

moving image illustrating predictive back texture

In Android 13, we launched a predictive again gesture for Android units resembling telephones, massive screens, and foldables. It’s a part of a multi-year launch; when absolutely carried out, this characteristic will let customers preview the vacation spot or different results of a again gesture earlier than absolutely finishing it, permitting them to resolve whether or not to proceed or keep within the present view.

The Exercise APIs for Predictive Again for Android are steady and now we have up to date the finest practices for utilizing the supported system again callbacks; BackHandler (for Compose), OnBackPressedCallback, or OnBackInvokedCallback. We’re excited to see Google apps undertake Predictive Again together with PlayStore, Calendar, Information, and TV!

Within the Exercise 1.8 alpha releases, The OnBackPressedCallback class now incorporates new Predictive Again progress callbacks for dealing with the again gesture beginning, progress all through the gesture, and the again gesture being canceled along with the earlier handleOnBackPressed() callback for when the again gesture is dedicated. We additionally added ComponentActivity.setUpEdgeToEdge() to simply arrange the edge-to-edge show in a backward-compatible method.

Exercise updates for extra constant Photograph Picker expertise

The Android picture picker is a browsable interface that presents the person with their media library. In Exercise 1.7.0, the Photograph Picker exercise contracts have been up to date to comprise an extra fallback that enables OEMs and system apps, resembling Google Play providers, to offer a constant Photograph Picker expertise on a wider vary of Android units and API ranges by implementing the fallback motion. Learn extra within the Photograph Picker All over the place weblog.

Incremental Knowledge Fetching

The Paging library means that you can load and show small chunks of information to enhance community and system useful resource consumption. App information will be loaded steadily and gracefully inside RecyclerViews or Compose lazy lists.

In Paging Compose 1.0.0-alpha19, there may be assist for all lazy layouts together with customized layouts supplied by the Put on and TV libraries. To assist extra lazy layouts, Paging Compose now supplies barely decrease degree extension strategies on LazyPagingItems in itemKey and itemContentType. These APIs concentrate on serving to you implement the important thing and contentType parameters to the usual objects APIs that exist already for LazyColumnLazyVerticalGrid in addition to their equivalents in APIs like HorizontalPager. Whereas these modifications do make the LazyColumn and LazyRow examples a couple of strains longer, it supplies consistency throughout all lazy layouts.

2. Efficiency Optimization of Purposes

Utilizing efficiency libraries means that you can construct performant apps and determine optimizations to keep up excessive efficiency, leading to higher end-user experiences.

Bettering Begin-up Occasions

Baseline Profiles will let you partially compile your app at set up time to enhance runtime and launch efficiency, and are getting huge enhancements in new tooling and libraries:

Jetpack supplies a brand new Baseline Profile Gradle Plugin in alpha, which helps AGP 8.0+, and will be simply added to your challenge in Studio Hedgehog (now in canary). The plugin helps you to automate the duty of working era duties, and pulling profiles from the gadget and integrating them into your construct both periodically, or as a part of your launch course of.

The plugin additionally means that you can simply automate the brand new Dex Structure Optimization characteristic in AGP 8.1, which helps you to outline BaselineProfileRule exams that accumulate courses used throughout startup, and transfer them to the first dex file in a multidex app to extend locality. In a big app, this will enhance chilly startup time by 30% on high of Baseline Profiles!

Macrobenchmark 1.2 has shipped quite a lot of new options in alpha, resembling Energy metrics and Customized hint metrics, era of Baseline Profiles with out root on Android 13, and recompilation with out clearing app information on Android 14.

You may learn the whole lot in depth within the weblog “What’s new in Android Efficiency“.

3. Person Interface Libraries and Steerage

A number of modifications have been made to our UI libraries to offer higher assist for large-screen compatibility, foldables, and emojis.

Jetpack Compose

Jetpack Compose, Android’s fashionable toolkit for constructing native UI, lately had its Might 2023 launch which incorporates new options for textual content and layouts, continued efficiency enhancements, enhanced tooling assist, elevated assist for giant screens, and up to date steerage. You may learn extra within the What’s New in Jetpack Compose I/O weblog to study extra.

Look

The Look library, now in 1.0-beta, helps you to develop app widgets optimized for Android cellphone, pill, and foldable homescreens utilizing Jetpack Compose. The library offers you the newest Android widget enhancements out of the field, utilizing Kotlin and Compose.

Compose for TV

With the alpha launch of the TV library, now you can construct experiences for Android TV utilizing parts optimized for the lounge expertise. Compose for TV unlocks all the advantages of Jetpack Compose in your TV apps, permitting you to construct apps with much less code, simpler upkeep and a contemporary Materials 3 look straight out of the field. See the Compose for TV weblog for particulars.

Materials 3 for Compose

Materials Design 3 is the subsequent evolution of Materials Design, enabling you to construct expressive, spirited and private apps. It’s the beneficial design system for Android apps and the 1.1 steady launch brings thrilling new options resembling backside sheets, date and time pickers, search bars, tooltips, and added extra movement and interplay assist. Learn extra within the launch weblog.

Understanding Window State

The brand new WindowManager library helps builders adapt their apps to assist multi-window environments and new gadget kind elements by offering a standard API floor with assist again to API degree 14.

In 1.1.0-beta01, new options and capabilities have been added to exercise embedding and window structure that lets you optimize your multi-activity apps for giant screens. With the 1.1 launch of Jetpack WindowManager, exercise embedding APIs are not experimental and are beneficial for multi-activity purposes to offer improved massive display layouts. Try the What’s new in WindowManager 1.1.0-beta01 weblog for particulars and migration steps.

Different key updates

Kotlin Multiplatform

We proceed to experiment with utilizing Kotlin Multiplatform to share enterprise logic between Android and iOS. The Collections 1.3.0-alpha03 and DataStore 1.1.0-alpha02 have been up to date so now you can use these libraries in KMM initiatives. If you’re utilizing Kotlin Multiplatform in your app, we wish your suggestions!

This was a have a look at all of the modifications in Jetpack over the previous few months that will help you construct apps extra productively. For extra particulars on every Jetpack library, take a look at the AndroidX launch notes, shortly discover related libraries with the API picker and watch the Google I/O talks for extra highlights.

Java is a trademark or registered trademark of Oracle and/or its associates.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments