Jetpack encompasses a collection of Android libraries that incorporate best practices and provide backwards compatibility in your Android apps.
The Jetpack guide to app architecture provides an overview of the best practices and recommended architecture to consider as you build your Android app.
The following sections cover how you can get started using Jetpack components.
Use a Jetpack library in your app
All Jetpack components are available on the Google Maven repository.
Open the settings.gradle
file add the google()
repository in the
dependencyResolutionManagement { repositories {...}}
block as shown below:
Groovy
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() jcenter() } }
Kotlin
dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() jcenter() } }
You can then add Jetpack components, such as architecture components like LiveData
and ViewModel, in your module's
build.gradle
file, as shown here:
Groovy
dependencies { def lifecycle_version = "2.2.0" implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version" ... }
Kotlin
dependencies { val lifecycle_version = "2.2.0" implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version") implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version") ... }
Many Jetpack libraries provide Android KTX extensions as shown above with lifecycle-livedata-ktx
and lifecycle-viewmodel-ktx
.
The KTX extensions build upon the Java-based API, taking advantage of Kotlin-specific language features.
To learn of new Jetpack library releases, check out the Releases page.
Kotlin-based and Java-based API reference pages are available for all Jetpack libraries.
Verify Jetpack dependencies (optional)
As of June 2023, the Jetpack team signs Jetpack libraries. These signatures allow developers to verify that the library artifacts are built and signed by Google. A library is eligible for signature verification once it publishes an update.
If your Android project has signature verification enabled, follow these steps to verify Jetpack dependencies in the Gradle project:
Add Google's trusted keys to the
<trusted-keys>
section in$PROJECT_ROOT/gradle/verification-metadata.xml
:<trusted-keys> <trusted-key id="8461efa0e74abae010de66994eb27db2a3b88b8b"> ... </trusted-key> <trusted-key id="a5f483cd733a4ebaea378b2ae88979fb9b30acf2"> ... </trusted-key> ... </trusted-keys>
Add a
<trusting group>
entry for each library that the project is using. Here's an example for theandroidx.fragment
andandroidx.emoji2
libraries:<trusted-keys> <trusted-key id="8461efa0e74abae010de66994eb27db2a3b88b8b"> <trusting group="androidx.fragment"/> <trusting group="androidx.emoji2"/> </trusted-key> <trusted-key id="a5f483cd733a4ebaea378b2ae88979fb9b30acf2"> <trusting group="androidx.fragment"/> <trusting group="androidx.emoji2"/> </trusted-key> ... </trusted-keys>
For issues with dependency verification, visit Gradle's guide on troubleshooting dependency verification.
Finally, details on our trusted key can be viewed on Ubuntu's keyserver site.
Take advantage of Jetpack
Jetpack libraries may be used alone or in combination to address different needs in your apps.
- WorkManager for your background scheduling needs.
- Room for data storage persistence.
- Navigation to manage your application navigation flow.
- CameraX for your camera app needs.
- See the Overview of all the Jetpack libraries.
Jetpack libraries are published in the androidx
namespace. If your project
currently uses the Android Support Library, read how to migrate to the
androidx namespace.
To learn more about using Jetpack, check out these pages:
Additional resources
Online training
- Developing Android Apps with Kotlin (Udacity course)
Sample code
- The Sunflower demo app uses many different Jetpack components to demonstrate Android development best practices.