When we are building our Android apps we want to make sure we are using our time efficiently and not reinventing the wheel by leveraging tools and libraries available to us, and then focusing our efforts on the critical aspects of our app that will deliver a great user experience to our customers.
As we release our Android apps they will be distributed through the Google Play Store with an audience all across the world with a variety of different devices available with different Android API Levels installed. This is why it is vital that we get backwards compatibility correct.
In addition to this the Android app marketplace is fast moving and we need to be able to respond quickly to user feedback to enhance our app to deliver greater functionality which makes the maintainbility of our app just as important.
Android Jetpack offers components, tools and architecture guidance to help us speed up Android app development. It helps us address backwards compatibility, maintainbility and recudes the amount of boiler plate code we need to write.
In this post I will go through the 29 Android Jetpack components available today and include some information on how these Jetpack components can be leveraged to benefit your Android app.
What is Android Jetpack?
Android Jetpack is a set of resources for Android developers includes components, tools and architecture guidance to help accelerate Android development of high quality apps.
All of the Android Jetpack libraries exist under the androidx.* package and they are built to be backwards compatible across Android API releases.
Android Jetpack components exist under 4 categories.
- Jetpack Foundation Components
- Jetpack Architecture Components
- Jetpack Behaviour Components
- Jetpack UI Components
To learn more about Android Jetpack check out the YouTube video below from the Android Developers channel.
Jetpack Foundation Components
Android Jetpack has a total of 9 foundation components which include the following.
- Android KTX
- AppCompat
- Car
- Benchmark
- Multidex
- Security
- Test
- TV
- Wear OS by Google
Android KTX
Android KTX is a set of Kotlin extensions for Jetpack APIs and other Android APIs that will assist you in writing more concise and natural Kotlin code for your Android app by leveraging key features of the Kotlin programming language including the following.
- Extension functions
- Extension properties
- Lambdas
- Named parameters
- Parameter default values
- Coroutines
Android KTX is organised into different modules which consist of multiple packages.
The list of AndroidX modules currently available under Android KTX include the following.
- Core KTX
- Collection KTX
- Fragment KTX
- Lifecycle KTX
- LiveData KTX
- Navigation KTX
- Palette KTX
- Reactive Streams KTX
- SQLite KTX
- ViewModel KTX
- WorkManager KTX
There are also other modules available under Android KTX that sit outside of AndroidX which include the following.
- Firebase KTX
- Play Core KTX
To learn more about Android KTX check out the documentation available at developer.android.com
As I covered in a post for beginners wanting chose a programming language for Android app development, in May 2019 Google made an announcement that Android app development will become increasingly Kotlin first. If you don’t already know Kotlin, you may want to check out my post below to find out about some of the benefits of learning Kotlin.
AppCompat
The AppCompat library adds support for showing an Action Bar within your Android App. It also adds support for Material Design for Android.
Key classes in the v7 AppCompat library include the following.
- ActionBar
- AppCompatActivity
- AppCompatDialog
- ShareActionProvider
To learn more about AppCompat check out the documentation available at developer.android.com
Car
For building Android apps for cars there are two options available to you, Android Auto and Android Automotive OS.
To use Android Auto, users need to connect an Android phone with the Android Auto app installed to their car display to utilise Android apps that have been designed with the user experience of a driver in mind.
Android Automotive OS is a Android based infotainment system built into the car display. Apps are downloaded directly to the unit and are run from the car display.
Using Jetpack libraries you are able to create two different types of apps, media apps and messaging apps, for Android Auto and Android Automotive OS.
To learn more about Android for Cars check out the video below as well as the documentation available at developer.android.com
Benchmark
Jetpack offers ways to measure the performance of your Java or Kotlin code inside Android Studio as well as via your Continuous Integration job with the Jetpack Benchmark library.
The Benchmark library supports warm up, measures your code performance and outputs benchmarking results to the Android Studio console.
To learn more about the Jetpack Benchmark library check out the video below as well as the documentation available at developer.android.com
Multidex
Android apps are compiled into DEX files also known as Dalvik Executables which are then subsequently packaged into an .APK file.
DEX files have a limitaiton where if your app and the libraries it references exceeds 65,536 methods you will encounter a build error. To solve for this limitation Jetpack provides a support library to cater to apps with multiple DEX files.
To learn more about Multidex check out the documentation available at developer.android.com
Security
Jetpack offers a Security library that handles security best practices for reading and writing data at rest and key creation and verification.
In the Jetpack Security library there is the EncryptedFile class used for reading and writing encrypted files securely.
Also in the Jetpack Security library there is the EncryptedSharePreferences class used to edit a users set of shared preferences securely.
To learn more about the Jetpack Security library check out the documentation available at developer.android.com
Test
Jetpack offers an Android testing framework for unit and runtime user interface tests.
To learn more about the Jetpack Android testing framework library check out the documentation available at developer.android.com as well as the article I wrote on testing your Android app before publishing.
TV
Jetpack offers various components to assist you in developing apps for Android Smart TVs. Android TV apps use the same structure as those built for smart phones and tablets but there are some notable differences.
These differences include handling navigation using a d-pad on a TV remote, making content in your Android TV app searchable and displaying the relevant content on the TV’s home page based on what the user has recently engaged with.
Android TV apps make use of the Jetpack Leanback library for addressing these concerns. Check out the online documentation for each of them to learn more.
androidx.leanback.app
androidx.leanback.database
androidx.leanback.graphics
androidx.leanback.media
androidx.leanback.preference
androidx.leanback.system
androidx.leanback.widget
androidx.leanback.widget.picker
To learn more about the Jetpack libraries for Android TV check out the documentation available at developer.android.com.
Wear OS By Google
Also included in Jetpack are components to enable development of apps for Wear OS, Google’s platform for smart watches.
Wear OS offers a three different options for development.
- Wear apps
- Watch faces
- Complication data providers
Wear apps run on the smart watch and can leverage device features such as sensors and the GPU.
Watch faces can be created and customised to with custom drawings, colours, animations and contextual information.
Complication data providers are used to supply watch faces with a custom set of data such as text, images and more.
Wear OS also support features such as notifications and actions on Google.
To learn more about Wear OS check out the video below as well as the documentation available at developer.android.com
Jetpack Architecture Components
Jetpack has a total of 8 architecture components which include the following.
- Data Binding
- Lifecycles
- LiveData
- Navigation
- Paging
- Room
- ViewModel
- WorkManager
Data Binding
The Jetpack component for Data Binding allows you to bind user interface components in your layout to data sources in a declarative format rather than programmatically.
Using the Data Binding Jetpack library you can avoid making findViewById(…) calls to locate various user interface elements in your Android app such as a TextView’s and EditText’s instead you can reference the reference the variable inside the layout file directly to bind it to the variable.
To learn more about Data Binding check out the documentation available at developer.android.com
Lifecycles
The Android Jetpack Lifecycle architecture component allows you to manage the lifecycles of your activities and fragments.
To learn more about the Lifecycle architecture component check out the documentation available at developer.android.com.
LiveData
LiveData is an observable data holder that is lifecycle aware. Inside your View you can add an observer to the LiveData so that when the LiveData is updated, your View (for example a Activity or Fragment) is notified so that you can update your user interface with the new data. The ViewModel is generally used to update the LiveData, however LiveData can also be modified in the repository on certain events such as handling an API response.
To learn more about LiveData and how to use it check out the documentation available at developer.android.com and the article I wrote around consuming a REST API using the Model View ViewModel pattern which utilises the LiveData Jetpack architecture component.
Navigation
As a part of the Android Jetpack suite of libraries and tools, the Navigation Architecture Component has been made available to Android developers to help simplify navigation within your Android app.
The Navigation Architecture Components utilises the Navigation Graph, the NavHostFragment and the NavController to enable navigation within the Android app.
To learn more about the Navigation Jetpack architecture component and how to use it check out the documentation available at developer.android.com and the article I wrote around moving between fragments inside a single activity using the Navigation Jetpack architecture component.
Paging
The Paging architecture component supports the gradual loading information on demand from your data source which could be a backend server, on device cache or a combination of a network service and a cache on the device.
Using paging to load partial sets of data reduces the demand on system resources and network bandwidth.
To learn more about the Paging architecture component check out the documentation available at developer.android.com.
Room
The Room architecture component is a persistence library that provides an abstraction layer over a SQLite database. Room allows you to keep a cache of your app data allowing it to be accessible even in cases on network connectivity issues.
To learn more about the Room Jetpack architecture component check out the documentation available at developer.android.com.
ViewModel
View models are objects that provide data for user interface components that survive configuration changes such as device rotations that cause an Activity to be recreated potentially resulting loss of data. View models reduce the complexity of your Activity and Fragment classes by shifting responsibility of code relating to the data to shown in the user interface of out of the Activity and Fragment and into the ViewModel.
To learn more about ViewModel and how to use it check out the documentation available at developer.android.com and the article I wrote around consuming a REST API using the Model View ViewModel pattern which utilises the ViewModel Jetpack architecture component.
WorkManager
Android Jetpack offers the WorkManager component to assist in managing background tasks in your Android app.
WorkManager is backwards compatible until Android API Version 14 and will use JobScheduler or BroadcastReceiver with AlarmManager behind the scenes based on the devices API version.
To learn more about the WorkManager architecture component check out the documentation available at developer.android.com.
Jetpack Behaviour Components
Android Jetpack has a total of 7 behaviour components which include the following.
- CameraX
- Media & Playback
- Notifications
- Permissions
- Preferences
- Sharing
- Slices
CameraX
CameraX is a Jetpack support library that simplifies the developer experience for creating Android apps that utilise the camera. CameraX is backwards compatible up until Android 5.0 (API level 21).
CameraX offers the following features.
- Image preview: which offers the ability to preview images in your app from the camera
- Image analysis: which offers the ability to perform image processing, computer vision or machine learning against an image available from the camera
- Image capture: which offers the ability to save images taken from the camera with different quality settings
- Vendor extensions: which offers the ability to apply different effects to the image before it is captured from the camera
To learn more about CameraX check out the documentation available at developer.android.com
Media & Playback
Jetpack offers a backwards compatible APIs for media playback, routing along with support for Google Cast.
The Media & Playback libraries offered by Jetpack can help you make Android apps that playback video and audio using media sessions and media controllers.
To learn more about Media & Playback for Android Jetpack check out the documentation available at developer.android.com.
Notifications
Jetpack offers a backwards compatible solution for notifications that supports smart phones, tablets, smart watches through Android Wear and smart cars through Android for Cars.
In addition to displaying a notification on the device, the notification library has evolved to support different features including the following.
- Notification actions
- Expandable notifications
- Grouped notifications
- Notifications that can be updated
- Notification channels
- Notification importance
- Notification badges
- Custom views for notifications
To learn more about Notifications check out the documentation available at developer.android.com
Permissions
Android Jetpack offers compatibility APIs for checking and requesting app permissions to protect the privacy of the user.
To learn more about Permissions for Android Jetpack check out the documentation available at developer.android.com.
Preferences
Android Jetpack offers a Preferences library to create interactive settings screens in your Android app. Preferences can be grouped in categories and split into multiple screens.
To learn more about Preferences for Android Jetpack check out the documentation available at developer.android.com.
Sharing
Android Jetpack offers a method of sharing data from your Android app to other apps on your device.
To learn more about Sharing for Android Jetpack check out the documentation available at developer.android.com.
Slices
Android Jetpack allows you to create flexible UI elements that can display app data outside the app using Slices.
To learn more about Slices for Android Jetpack check out the documentation available at developer.android.com.
Jetpack UI Components
Android Jetpack has a total of 6 user interface components which include the following.
- Animations & Transitions
- Emoji
- Fragment
- Layout
- Palette
- ViewPager2
Animations & Transitions
Android Jetpack offers you the ability to move widgets and transition between screens in inside your app with animations and transitions.
To learn more about Animations & Transitions for Android Jetpack check out the documentation available at developer.android.com.
Emoji
Emoji from Android Jetpack enable an up-to-date emoji font on older platforms.
To learn more about Emoji for Android Jetpack check out the documentation available at developer.android.com.
Fragment
Android Jetpack offers Fragments as a basic unit of composable UI for Android apps.
To learn more about Fragments for Android Jetpack check out the documentation available at developer.android.com.
Layout
Android Jetpack features different algorithms for to lay out widgets in your Android app.
To learn more about Layouts for Android Jetpack check out the documentation available at developer.android.com.
Palette
Palette which is a part of Android Jetpack allows you to pull useful information out of color palettes to use in your Android app.
To learn more about Palette for Android Jetpack check out the documentation available at developer.android.com.
ViewPager2
Android Jetpack offers ViewPager2 which allows you to create swipe views between tabs in your Android app.
To learn more about ViewPager2 for Android Jetpack check out the documentation available at developer.android.com.