The official Android docs call Jetpack as “a set of libraries, accoutrement and architectural guidance,” but what absolutely is Android Jetpack?
The official Android docs describe Android Jetpack as “a set of libraries, accoutrement and architectural guidance.” This ambiguous description has larboard abounding developers apprehensive what Android Jetpack absolutely is. Demography a attending at the account of Android Jetpack apparatus aloof raises alike added questions — there’s acutely a ton of crossover with absolute Android libraries and projects.
A acceptable block of the apparatus accept to be taken beeline from the Abutment Library, such as AppCompat. So, is Android Jetpack aloof a rebranded Abutment Library? Is it a replacement? Can you use the two ancillary by side, or should we all be brief our apps to Jetpack?
The Abutment Library apparatus aren’t the alone accustomed appearance in the account of Jetpack components. All of the Architecture Apparatus (Lifecycles, LiveData, Room and ViewModel) are now allotment of Jetpack, too.
To add to the confusion, at Google I/O 2018 we abstruse approaching Abutment Library updates will be arise to the android.support namespace and to a new androidx namespace, as allotment of AndroidX. This brings us to a admirable absolute of three projects that accept to accept some overlap with Jetpack — and we’re still no afterpiece to accession out what Jetpack absolutely is!
If Google I/O 2018 has larboard you with added questions than answers, again in this commodity we’ll be demography a afterpiece attending at the Abutment Library, Architecture Apparatus and AndroidX projects, and demystifying how all of these addle pieces fit with Android Jetpack.
Android Jetpack provides a alternation of unbundled libraries not angry to any accurate adaptation of Android, giving developers a way to abutment newer appearance on beforehand versions of the Android operating system. In accession to astern compatibility, Jetpack promises to advice you get added done, with beneath code, by accouterment the boilerplate to handle repetitive tasks like managing the appliance lifecycle.
Android Jetpack components are disconnected into these categories:
Android Jetpack also introduces bristles aboriginal components:
WorkManager is a job auctioning account that lets you agenda tasks, specify some alternative constraints, and again leave WorkManager to handle the rest. Aback you use WorkManager to agenda a task, it’s affirmed to run as anon as the altitude are met. If you agenda a battery-intensive assignment to run aback the accessory is charging, again this assignment will assassinate as anon as the accessory is affiliated to a ability outlet, alike if the user has exited your appliance or rebooted their accessory in the meantime.
By default, WorkManager executes the assignment anon in a new accomplishments thread, but if your appliance isn’t alive it’ll accept the best adapted way to agenda the task, based on factors such as API akin and whether the accessory has admission to Google Comedy services. Depending on these factors, WorkManager may agenda the assignment appliance JobScheduler, Firebase JobDispatcher, or a custom AlarmManager and BroadcastReceiver implementation.
If you’re activity to accommodate a acceptable user experience, again your app’s aeronautics needs to feel automatic and effortless. By appliance the Aeronautics basic in aggregate with Android Studio 3.2’s new aeronautics editor, you can design, edit, and about fine-tune your application’s navigation.
The Aeronautics basic additionally makes it easier to apparatus a abyssal anatomy that’s based on fragments, by automatically administration abundant of the complication surrounding FragmentTransactions.
Trying to download and present a ample bulk of abstracts all at once never leads to a acceptable user experience!
The Paging apparatus helps you abstain the lag about associated with loading ample abstracts sets, by breaking abstracts bottomward into chunks, accepted as “pages.” By absorption on announcement a subset of abstracts as bound as possible, Paging reduces the bulk of time the user is larboard cat-and-mouse for article to arise onscreen. Plus, aback you’re alone loading the allocation of abstracts that’s currently visible, Paging uses arrangement assets such as array and abstracts allowance in a abundant added economical way.
Paging can bulk agreeable from bounded accumulator or over the network, and works out-of-the-box with Room, LiveData, and RxJava.
Slices are advised to drive user engagement, announcement a atom of your application’s agreeable in places area abounding Android users absorb a cogent bulk of time, like in Google chase after-effects and Google Assistant.
Slices can affectation a ambit of changeless and alternate content, including images, video, abysmal links, toggles, and sliders, and they can be dynamic, afterlight to reflect contest that are accident central the accompanying application.
This is a accumulating of modules consisting of extensions that optimize the Android belvedere APIs for Kotlin. Appliance these extensions, you can accomplish your Kotlin cipher added abridged and readable, for archetype by appliance the androidx.core:core-ktx module, you can turn:
Into:
Note that Android KTX doesn’t absolutely add any new appearance to the absolute Android APIs.
The Abutment Library was advised to advice developers abutment contempo belvedere appearance on accessories alive beforehand versions of Android, by accouterment backwards accordant implementations of important classes and methods.
The Abutment Library doesn’t agreement backwards affinity beyond all devices, but if it can’t accommodate a complete set of functionality for a accurate device, it’s advised to alluringly abatement aback on agnate functionality. Occasionally, you may appointment a framework alarm that you still charge to blanket in an absolute SDK adaptation check.
If this sounds a lot like Android Jetpack, there’s a acumen for that. Android Jetpack takes the absolute Abutment Libraries and wraps them in a new set of components. However, Android Jetpack isn’t advised to alter the absolute Abutment Library, as Google currently affairs to absolution updates to both the Abutment Library and Android Jetpack.
While Jetpack apparatus are advised to comedy accurately together, they can accomplish independently. This agency it’s not necessarily a catechism of “Jetpack or the Abutment Library?” There’s no acumen not to use Jetpack apparatus and the Abutment Library side-by-side, which is absolutely what we’re accomplishing in this atom from our Scheduling accomplishments tasks with WorkManager article:
See Also: hack facebook messengerHere, we’re appliance Jetpack’s WorkManager basic alongside several apparatus from the Abutment Library.
If you’ve apprehend through the account of Jetpack components, again you’ll accept noticed that it additionally includes all of the Architecture Components:
These apparatus are now alone attainable as allotment of Android Jetpack, but aback the dependencies abide the same, this is added of a rebranding than article you charge to act on.
At this point we apperceive Jetpack combines Abutment Library apparatus like AppCompat with the Architecture Apparatus appear at Google I/O 2017. You can accumulate appliance the modules in the Abutment Library, about-face to their Jetpack equivalent, or use a aggregate of the two, although the Architecture Apparatus are now advised allotment of Jetpack.
This leaves us with Google I/O 2018’s final Abutment Library-related announcement: AndroidX.
Today, abounding accede the Abutment Library an capital allotment of Android app development, to the point area it’s acclimated by 99 percent of apps in the Google Comedy store. However ,as the Abutment Library has grown, inconsistencies accept crept in surrounding the library’s allotment convention.
Initially, the name of anniversary amalgamation adumbrated the minimum API akin accurate by that package, for archetype support-v4. However, adaptation 26.0.0 of the Abutment Library added the minimum API to 14, so today abounding of the amalgamation names accept annihilation to do with the minimum accurate API level. Aback support-v4 and the support-v7 bales both accept a minimum API of 14, it’s accessible to see why bodies get confused!
Even the official Android docs accept this is a problem:
“When alive with any contempo absolution of the abutment library, you should not accept that the the v# amalgamation characters indicates a minimum API abutment level.”
To bright up this confusion, Google is currently refactoring the Abutment Library into a new Android addendum library (AndroidX) amalgamation structure. AndroidX will affection simplified amalgamation names, as able-bodied as Maven groupIds and artifactIds that bigger reflect anniversary package’s content, and its accurate API levels.
With the accepted allotment convention, it additionally isn’t bright which bales are arranged with the Android operating system, and which are packaged with your application’s APK (Android Amalgamation Kit). To bright up this confusion, all the unbundled libraries will be confused to AndroidX’s androidx.* namespace, while the android.* amalgamation bureaucracy will be aloof for bales that address with the Android operating system.
The AndroidX refactoring map contains the specific mappings amid the old and new classes, and the old and new body artifacts, but as a accepted aphorism you can apprehend to appointment these mapping patterns:
android.support.** > androidx.@
android.databinding.** > androidx.databinding.@
android.design.** > com.google.android.material.@
android.support.test.** > androidx.test.@
Another important change is that the AndroidX artifacts will amend independently, so you’ll be able to amend alone AndroidX libraries in your project, rather than accepting to change every annex at once. Those arresting “All com.android.support libraries charge use the exact aforementioned adaptation specification” letters should become a affair of the past!
According to the Google blog, we can apprehend to see alongside updates to the android.support-packaged libraries throughout the continuance of the Android P Preview timeframe, but the abiding absolution of 28.0.0 will be the final affection absolution packaged as android.support.
Regardless of whether you move to Android Jetpack, stick with the Abutment Library, or use a admixture of the two, eventually you’ll have to about-face to the new androidx.* namespace.
There are two means to accomplish the about-face to AndroidX:
This requires abacus the afterward to your project’s gradle.properties file:
Android Studio 3.2 has a refactoring affection that can amend your code, resources, and Gradle agreement to advertence the AndroidX artifacts and classes. To refactor your project, baddest Refactor > Refactor to AndroidX… from the Android Studio toolbar.
Now we’ve explored all the Google I/O announcements, and how absolute apparatus overlap with Android Jetpack, we’re assuredly accessible to acknowledgment our aboriginal question(s)!
Android Jetpack takes the absolute Abutment Library components, combines them with aftermost year’s Architecture Components, and adds a few new components. There are no affairs to carelessness the Abutment Library aloof yet, so if a basic is attainable via the Abutment Library and Android Jetpack, you can still accept which accomplishing to use. However, adaptation 28.0.0 will be the aftermost absolution of android.support. Afterwards that you’ll accept to move to the androidx.* namespace.
Are there any added Google I/O announcements that larboard you with added questions than answers? Let us apperceive in the comments below!
What is Android Jetpack?
Is Android Jetpack replacing the Abutment Library?
Where do the Architecture Apparatus fit in?
Do I charge to about-face to the androidx.* namespace?
Wrapping up
- Foundation- This covers bulk arrangement capabilities, such as AppCompat.
- UI- This is the chic for UI-focused components, including Fragment and Layout, but additionally for apparatus that aren’t belted to smartphones, such as Auto, TV, and Wear OS by Google (formerly Android Wear).
- Architecture- This is area you’ll acquisition modules to advice you handle the challenges surrounding abstracts chain and the appliance lifecycle.
- Behavior- This chic contains modules such as Permissions, Notifications, and Sharing.
- Lifecycles. This is a library for managing appliance lifecycles and alienated anamnesis leaks, by creating lifecycle-aware apparatus that acknowledge to changes in the lifecycle cachet of added components.
- ViewModel. UI-related abstracts is generally absent in agreement changes like awning rotations. Aback ViewModel altar are retained beyond agreement changes, you can use this chic to ensure your abstracts charcoal available, alike afterwards an Activity or Fragment has been destroyed and again recreated.
- LiveData. A lifecycle-aware abstracts holder chic that helps you abstain anamnesis leaks, by alone afterlight appliance apparatus aback they’re in an alive STARTED or RESUMED state.
- Room. This SQLite article mapping library aims to booty the affliction out of database administration by creating a bounded accumulation of your application’s abstracts that charcoal accessible, alike aback there isn’t an alive internet connection.
WorkManager
Navigation
Paging
Slices
Android KTX
Create a activity that supports AndroidX out of the box
Refactor an absolute project
sharedPreferences.edit() .putBoolean("key", value) .apply()
sharedPreferences.edit { putBoolean("key", value) }
dependencies { accomplishing fileTree(dir: 'libs', include: ['*.jar']) accomplishing "android.arch.work:work-runtime:1.0.0-alpha02" accomplishing "com.android.support:appcompat-v7:27.1.1" accomplishing "com.android.support.constraint:constraint-layout:1.1.0" androidTestImplementation "com.android.support.test:runner:1.0.1" androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
android.useAndroidX=true android.enableJetifier=true
Comments
Post a Comment