How to import Room Persistence Library to an Android project

后端 未结 13 1196
执笔经年
执笔经年 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条回答
  •  闹比i
    闹比i (楼主)
    2021-02-05 00:13

    open build.gradle(Project: projectName) and add this lines if it doesn't exist.

    This enables access to google repository

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

    next open build.gradle(Module:app) and add this two lines to existing dependencies

    For Java

    def room_version = "1.1.0"
    implementation "android.arch.persistence.room:runtime:$room_version"
    annotationProcessor "android.arch.persistence.room:compiler:$room_version"
    

    For Kotlin

    paste this line outside of the dependencies or android scope at the top where kotlin plugins are applied

    apply plugin: 'kotlin-kapt'
    

    add this lines to dependencies

    def room_version = "1.1.0"
    implementation "android.arch.persistence.room:runtime:$room_version"
    kapt "android.arch.persistence.room:compiler:$room_version"
    

    to keep yourself updated with the recent dependencies version visit mvn repository for room

    here you will find the latest version.

提交回复
热议问题