Add components to your project

Before getting started, read the Guide to app architecture for useful principles that apply to all Android apps and for guidance on using architecture components together.

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

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

Groovy

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

Kotlin

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

Declare 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 Migrate to AndroidX.

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.