[譯] Architecture Components 之 Adding Components to your Project

【目錄】

1. Architecture Components 之 Guide to App Architecture

2. Architecture Components 之 Adding Components to your Project

3. Architecture Components 之 Handling Lifecycles

4. Architecture Components 之 LiveData

5. Architecture Components 之 ViewModel

6. Architecture Components 之 Room Persistence Library

示例代碼連接


添加組件到項目中

警告:Architecture Components 仍是 alpha 版本,在 1.0 版本發佈以前可能有重大更改。html

Architecture Components 能夠從 Google 的 Maven 倉庫獲取。要使用它們,請按照下列步驟操做:java

添加 Google Maven 倉庫

默認狀況下 Android Studio 沒有配置訪問此庫。android

要將該庫添加到項目中,請打開項目中的 build.gradle 文件(不是應用或模塊下的)而且添加以下所示的高亮的行。git

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

添加 Architecture Components

打開應用或模塊中的 build.gradle 文件並將所需的組件添加爲依賴:github

  • 使用 LifecyclesLiveDataViewModel 須要添加: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 遷移須要添加:

      • testCompile "android.arch.persistence.room:testing:1.0.0-alpha1"
    • 使用 Room 的 RxJava 支持須要添加:

      • compile "android.arch.persistence.room:rxjava2:1.0.0-alpha1"

有關更多信息,請參閱添加構建依賴

相關文章
相關標籤/搜索