将 Room 的 @Database 添加到数据库摘要后,任务“:app:kaptGenerateStubsDebugKotlin”失败 class

Failed for task ':app:kaptGenerateStubsDebugKotlin' after adding Room's @Database to database abstract class

我正在尝试将 Room 实现到用 Kotlin 编写的 Android 应用程序中。在多次构建失败后,我指出了将@Database 添加到我的数据库时失败的问题 class.

package sample.service.local

import android.arch.persistence.room.Database
import android.arch.persistence.room.RoomDatabase
import sample.service.model.Announcement

@Database(entities = [Announcement::class], version = 1)
abstract class AnnounceDatabase: RoomDatabase() {
    abstract fun announceDAO(): AnnounceDAO
}

如果我注释掉带有@Database 的行,它就成功构建了。它的 DAO 和实体文件不应该是问题,因为我尝试在没有 @Database 的情况下使用它们构建并且它成功了。我也没有将它们添加到任何其他 classes 中;我刚刚创建了 3 个新文件,分别是这个数据库、它的 dao 和它的实体。

这里是 build.gradle(模块:app)

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: "kotlin-kapt"

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "sample"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        vectorDrawables.useSupportLibrary = true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding {
        dataBinding.enabled true
    }
}

project.ext {
    supportLibraryVersion = "26.1.0"
    daggerVersion = "2.13"
    butterKnifeVersion = "8.8.1"
    rxJavaVersion = "2.1.0"
    rxAndroidVersion = "2.0.1"
    lifecycleVersion = "1.0.0"
    roomVersion = "1.0.0"
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.google.android.gms:play-services-maps:11.8.0'
    implementation 'com.android.support:support-v4:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

// Android Support Library
implementation 'com.android.support:design:27.1.0'
implementation 'com.google.android.gms:play-services-location:11.8.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:cardview-v7:27.1.0'
implementation 'com.android.support:recyclerview-v7:27.1.0'
implementation 'com.android.support:support-annotations:27.1.0'
implementation 'com.android.support:support-compat:27.1.0'
implementation 'com.android.support:support-core-ui:27.1.0'

// Easy Permission
implementation 'pub.devrel:easypermissions:1.2.0'

// Lifecycle
implementation "android.arch.lifecycle:extensions:1.1.0"
annotationProcessor "android.arch.lifecycle:compiler:1.1.0"

// Kotlin binding
//    kapt 'com.android.databinding:compiler:3.1.0'

// Dagger core
kapt "com.google.dagger:dagger-compiler:$project.daggerVersion"
implementation "com.google.dagger:dagger:$project.daggerVersion"

// Dagger Android
kapt "com.google.dagger:dagger-android-processor:$project.daggerVersion"
implementation "com.google.dagger:dagger-android-support:$project.daggerVersion"

// Timber
implementation 'com.jakewharton.timber:timber:4.6.0'

// Simple Item Decoration
implementation 'com.bignerdranch.android:simple-item-decoration:1.0.0'

// Retrofit
implementation "com.squareup.retrofit2:retrofit:2.1.0"
implementation "com.squareup.retrofit2:converter-gson:2.1.0"
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
//    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0'

// RxJava & RxAndroid
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'

// PageIndicatorView
implementation 'com.romandanylyk:pageindicatorview:1.0.0@aar'

// Room
implementation "android.arch.persistence.room:rxjava2:$project.roomVersion"
implementation "android.arch.persistence.room:runtime:$project.roomVersion"
kapt "android.arch.persistence.room:compiler:$project.roomVersion"
testImplementation "android.arch.persistence.room:testing:$project.roomVersion"
}

这是项目的 gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.31'
repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.1'
    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

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

task clean(type: Delete) {
delete rootProject.buildDir
}

我运行gradlew clean build --stacktrace --debughere's error message

我们将不胜感激。

问题出在我的实体 class 中,我在其中使用 val 而不是 var 作为参数,所以我只是将它们全部更改为 var 并且问题解决了。

编辑: 我的 DAO class 也有一个问题,无法使用 ArrayList 代替 List