Skip to content

Most visited

Recently visited

navigation

Adding Components to your Project

Architecture Components are available from Google's Maven repository. To use them, follow these steps:

Add the Google Maven repository

Android Studio projects aren't configured to access this repository by default.

To add it to your project, open the build.gradle file for your project (not the ones for your app or module) and add the highlighted line as shown below:

allprojects {
    repositories {
        jcenter()
        google()
    }
}

Add Architecture Components

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

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

Main Dependencies

Includes Lifecycles, LiveData, ViewModel, Room, and Paging.

It also includes test helpers for testing LiveData as well as testing Room migrations.

dependencies {
    // ViewModel and LiveData
    implementation "android.arch.lifecycle:extensions:1.1.0"
    // alternatively, just ViewModel
    implementation "android.arch.lifecycle:viewmodel:1.1.0"
    // alternatively, just LiveData
    implementation "android.arch.lifecycle:livedata:1.1.0"

    annotationProcessor "android.arch.lifecycle:compiler:1.1.0"

    // Room (use 1.1.0-alpha2 for latest alpha)
    implementation "android.arch.persistence.room:runtime:1.0.0"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

    // Paging
    implementation "android.arch.paging:runtime:1.0.0-alpha5"

    // Test helpers for LiveData
    testImplementation "android.arch.core:core-testing:1.1.0"

    // Test helpers for Room
    testImplementation "android.arch.persistence.room:testing:1.0.0"
}
Java 8 Support for Lifecycles

If your app uses Java 8, we recommend using this library instead of android.arch.lifecycle:compiler.

dependencies {
    // Java8 support for Lifecycles
    implementation "android.arch.lifecycle:common-java8:1.1.0"
}
Optional Dependencies for RxJava and ReactiveStreams

Adds optional support for Room RxJava and LiveData ReactiveStreams.

dependencies {
    // RxJava support for Room (use 1.1.0-alpha1 for latest alpha)
    implementation "android.arch.persistence.room:rxjava2:1.0.0"

    // ReactiveStreams support for LiveData
    implementation "android.arch.lifecycle:reactivestreams:1.1.0"
}
Optional Dependencies for Guava

Adds support for Guava's Optional and ListenableFuture types in Room @DAO queries.

dependencies {
    // Guava support for Room
    implementation "android.arch.persistence.room:guava:1.1.0-alpha2"
}
Alternative import for lightweight Lifecycles only

Support library depends on this lightweight import. It provides Lifecycles without LiveData or ViewModel.

dependencies {
    // Lifecycles only (no ViewModel or LiveData)
    implementation "android.arch.lifecycle:runtime:1.1.0"
    annotationProcessor "android.arch.lifecycle:compiler:1.1.0"
}

For more information, see Add Build Dependencies.

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

在微信上关注 Google Developers

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)