更新到 SDK 31 后,Room 数据库停止工作:COuld Not find @Entity 导致 Room 无法构建

After update to SDK 31 Room Database stopped working: COuld Not find @Entity which causes Room to not Build

这是我在尝试构建项目时看到的。除了 Android 强制我在 Manifest 中更改的内容之外,我没有更改任何内容,我不知道此后该去哪里。

@Dao
interface SubscriberDAO {
@Insert
suspend fun insertSubscriber(subscriber: Subscriber): Long

@Update
suspend fun updateSubscriber(subscriber: Subscriber): Int

@Delete
suspend fun deleteSubscriber(subscriber: Subscriber): Int

@Query("DELETE FROM subscriber_data_table")
suspend fun deleteAll(): Int

@Query("SELECT * FROM subscriber_data_table")
fun getAllSubscribers(): LiveData<List<Subscriber>>

}

怎么了? 我尝试将 TargetSdk 改回 30,但仍然无效

Gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 31

    defaultConfig {
        applicationId "com.homeofficeprojects.samplearchitecturedatabasecoroutinesproject"
        minSdkVersion 21
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    buildFeatures{
        dataBinding = true
        // for view binding :
        // viewBinding = true
    }
    /*dataBinding{
        enabled = true
    }*/
}

dependencies {
    def lifecycle_version = "2.4.0"
    def room_version = "2.3.0"

    kotlin {
        experimental {
            coroutines "enable"
        }
    }

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.7.0'
    implementation 'androidx.appcompat:appcompat:1.4.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

    // ViewModel
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
    // LiveData
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
    // Annotation processor

    implementation("androidx.room:room-runtime:$room_version")
    // To use Kotlin annotation processing tool (kapt)
    kapt("androidx.room:room-compiler:$room_version")

    // optional - Kotlin Extensions and Coroutines support for Room
    implementation("androidx.room:room-ktx:$room_version")
    annotationProcessor("androidx.room:room-compiler:$room_version")



    //coroutines
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.0'


    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.3'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    implementation 'androidx.recyclerview:recyclerview:1.2.1'
    implementation 'androidx.cardview:cardview:1.0.0'
}

订阅者

package com.homeofficeprojects.samplearchitecturedatabasecoroutinesproject

import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "subscriber_data_table")
data class Subscriber(
    @PrimaryKey(autoGenerate = true)
    @ColumnInfo(name = "subscriber_id")
    var id: Int,

    @ColumnInfo(name = "subscriber_name")
    var name: String,

    @ColumnInfo(name = "subscriber_email")
    var email: String
) {
    //constructor(): this(0, "", "")
}

编辑:我添加了 Gradle 构建文件和订阅者 科特林 class 编辑 2:第二张图片,有关错误的更多信息

我最后在 reddit 上询问并被告知回滚 gradle 依赖项。 classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"ext.kotlin_version = "1.6.0"ext.kotlin_version = "1.5.31" 我不确定我会称之为前进的道路,但我可以继续我的项目,所以我称之为一个,直到真正的答案出现