How to import Room Persistence Library to an Android project

后端 未结 13 1193
执笔经年
执笔经年 2021-02-05 00:01

I recently saw the new feature announced on Google I/O Room Persistence Library to work with Sqlite databases on Android. I have been looking to the official documentation and I

13条回答
  •  抹茶落季
    2021-02-05 00:23

    Android doc:

    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()
        maven { url 'https://maven.google.com' }
        }
    }
    

    Add Architecture Components

    Open the build.gradle file for your app or module and add the artifacts that you need as dependencies:

    For Lifecycles, LiveData, and ViewModel, add:

    implementation "android.arch.lifecycle:runtime:1.0.0-alpha1"
    implementation "android.arch.lifecycle:extensions:1.0.0-alpha1"
    annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"
    

    For Room, add:

    implementation "android.arch.persistence.room:runtime:1.0.0-alpha1"
    annotationProcessor "android.arch.persistence.room:compiler:1.0.0-alpha1"
    

提交回复
热议问题