本文将介绍如何在项目中接入Architecture Components

在项目中使用Architecture Components

注意: Architecture Components 仍然处于 alpha 阶段,在1.0 release之前可能会有break change

1. 添加 Google Maven repository

打开 project root 目录下的 build.gradle,添加Google Maven repository

allprojects {
repositories {
jcenter()
+ maven { url 'https://maven.google.com' }
}
}

2. 添加 Architecture Components

修改 app module目录下的 build.gradle

compile "android.arch.lifecycle:runtime:1.0.0-alpha1"
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
  • 使用 Room, 添加:
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
testCompile "android.arch.persistence.room:testing:1.0.0-alpha1"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha1"