警告:Architecture Components 仍是 alpha 版本,在 1.0 版本發佈以前可能有重大更改。html
Architecture Components 能夠從 Google 的 Maven 倉庫獲取。要使用它們,請按照下列步驟操做:java
默認狀況下 Android Studio 沒有配置訪問此庫。android
要將該庫添加到項目中,請打開項目中的 build.gradle 文件(不是應用或模塊下的)而且添加以下所示的高亮的行。git
allprojects {
repositories {
jcenter()
maven { url 'https://maven.google.com' }
}
}
打開應用或模塊中的 build.gradle 文件並將所需的組件添加爲依賴:github
使用 Lifecycles,LiveData 和 ViewModel 須要添加:app
compile "android.arch.lifecycle:runtime:1.0.0-alpha1"maven
compile "android.arch.lifecycle:extensions:1.0.0-alpha1"ide
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"post
使用 Room 須要添加:測試
compile "android.arch.persistence.room:runtime:1.0.0-alpha1"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
使用測試 Room 遷移須要添加:
使用 Room 的 RxJava 支持須要添加:
有關更多信息,請參閱添加構建依賴。