Android Room Persistence library and Kotlin

前端 未结 6 722
迷失自我
迷失自我 2020-12-03 04:34

I am trying to write a simple app using Kotlin and Room Persistence Library. I followed the tutorial in the Android Persistence codelab.

Here is my AppDatabase<

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 04:42

    Try out these steps

    Step 1. Set the room_version in the project.gradle file

    buildscript {
        ext.kotlin_version = '1.1.51'
        ext.room_version = '1.0.0-alpha9-1'
    ...
    

    Step 2. Apply the kotlin-kapt plugin in the app.gradle file, and this solved my issue.

    apply plugin: 'com.android.application'
    apply plugin: 'kotlin-android'
    apply plugin: 'kotlin-android-extensions'
    apply plugin: 'kotlin-kapt'
    
    android {
        compileSdkVersion 26
        buildToolsVersion "26.0.1"
    ...
    

    Step 3. Add the kapt dependency in the app.gradle file

    dependencies {
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation "android.arch.persistence.room:runtime:$room_version"
        annotationProcessor "android.arch.persistence.room:compiler:$room_version"
        kapt "android.arch.persistence.room:compiler:$room_version"
    ...
    }
    

提交回复
热议问题