How to import Room Persistence Library to an Android project

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

    Bouncing off @Thracian's answer, here's what I had to do while following this documentation:

    https://codelabs.developers.google.com/codelabs/android-room-with-a-view-kotlin/#13

        /* Room */
        implementation 'androidx.room:room-runtime:2.1.0'
        kapt 'androidx.room:room-runtime:2.1.0'
    
        implementation 'androidx.room:room-compiler:2.1.0'
        kapt 'androidx.room:room-compiler:2.1.0'
        annotationProcessor 'androidx.room:room-compiler:2.1.0'
    
        implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha02'
        kapt 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha02'
    
        implementation 'androidx.room:room-ktx:2.1.0'
        kapt 'androidx.room:room-ktx:2.1.0'
    
        implementation 'android.arch.lifecycle:extensions:1.1.1'
        kapt 'android.arch.lifecycle:extensions:1.1.1'
    

    Also within android {} I had to add:

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    

    Despite what I've read, with Kotlin you still must use annotationProcessor

提交回复
热议问题