How to import Room Persistence Library to an Android project

后端 未结 13 1230
执笔经年
执笔经年 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:18

    Open the build.gradle file for your project (not the ones for your app or module) and add:

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

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

    dependencies {
    
        implementation "android.arch.persistence.room:runtime:1.0.0"
        annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
    
    }
    

    Reference: Android Adding Components

    0 讨论(0)
  • 2021-02-05 00:21
        * Add these in project level gradle
    
        allprojects {
            repositories {
                jcenter()
                maven { url 'https://maven.google.com' }
            }
        }
    
    
        ext {
            buildToolsVersion = "25.0.2"
            supportLibVersion = "25.3.1"
            archRoomVersion = "1.0.0-alpha1"
        }
    
    
        * Add these in module level gradle dependencies
    
    dependencies {
    
         compile 'android.arch.persistence.room:runtime:' + rootProject.archRoomVersion;
            annotationProcessor 'android.arch.persistence.room:compiler:' + rootProject.archRoomVersion;
    
    }
    
    0 讨论(0)
  • 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"
    
    0 讨论(0)
  • 2021-02-05 00:23

    As of July 2019 if you wish to use Room with Kotlin, AndroidX, Coroutines or RxJava add lines below.

       // Room
        implementation 'androidx.room:room-runtime:' + rootProject.roomVersion
        // For Kotlin use kapt instead of annotationProcessor
        kapt 'androidx.room:room-compiler:' + rootProject.roomVersion
        // optional - Kotlin Extensions and Coroutines support for Room
        implementation 'androidx.room:room-ktx:' + rootProject.roomVersion
        // optional - RxJava support for Room
        implementation 'androidx.room:room-rxjava2:' + rootProject.roomVersion
    
    0 讨论(0)
  • 2021-02-05 00:24

    It's possible to find the dependencies on the example codelab for the new architecture components.

    Root :

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

    For Room:

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

    For Lifecycle dependencies:

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

    Adding Rxjava2 objects as result for our queries:

      implementation 'android.arch.persistence.room:rxjava2:1.0.0-alpha1'
    

    Test migrations:

      testImplementation'android.arch.persistence.room:testing:1.0.0-alpha1'
    
    0 讨论(0)
  • 2021-02-05 00:27

    Try this to compile Room Persistence library

    implementation 'android.arch.persistence.room:runtime:1.1.1';
    annotationProcessor 'android.arch.persistence.room:compiler:1.1.1';
    

    And add this in root level build gradle

    allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    
    0 讨论(0)
提交回复
热议问题