Adding Components to your Project

Before getting started, we recommend reading the Architecture Components Guide to App Architecture. The guide has some useful principles that apply to all Android apps and shows how to use the Architecture Components together.

Architecture Components are available from Google's Maven repository. To use them, you must add the repository to your project.

Open the settings.gradle file and add the google() repository as shown below:

Groovy

dependencyResolutionManagement {
   ...
    repositories {
        google()
        jcenter()
    }
}

Kotlin

dependencyResolutionManagement {
    ...
    repositories {
        google()
        jcenter()
    }
}

Declaring dependencies

Open the build.gradle file for your app or module and add the artifacts that you need as dependencies. You can add dependencies for all Architecture Components, or choose a subset.

See the instructions for declaring dependencies for each Architecture Component in the release notes:

See AndroidX releases for the most up-to-date version numbers for each component.

For more information about the AndroidX refactor, and how it affects these class packages and module IDs, see the AndroidX refactor documentation.

Kotlin

Kotlin extension modules are supported for several AndroidX dependencies. These modules have the suffix "-ktx" appended to their names. For example:

Groovy

implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"

Kotlin

implementation("androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version")

becomes

Groovy

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

Kotlin

implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")

More information, including docs for Kotlin extensions, can be found in the KTX documentation.

Note: For Kotlin based apps, make sure you use kapt instead of annotationProcessor. You should also add the kotlin-kapt plugin.