Android room persistent: AppDatabase_Impl does not exist

前端 未结 21 1405
日久生厌
日久生厌 2020-11-29 01:09

My app database class

@Database(entities = {Detail.class}, version = Constant.DATABASE_VERSION)
public abstract class AppDatabase extends RoomDatabase {

            


        
21条回答
  •  迷失自我
    2020-11-29 01:29

    For those working with Kotlin, try changing annotationProcessor to kapt in the apps build.gradle

    for example:

    // Extensions = ViewModel + LiveData
    implementation "android.arch.lifecycle:extensions:1.1.0"
    kapt "android.arch.lifecycle:compiler:1.1.0"
    // Room
    implementation "android.arch.persistence.room:runtime:1.0.0"
    kapt "android.arch.persistence.room:compiler:1.0.0"
    

    also remember to add this plugin

    apply plugin: 'kotlin-kapt'
    

    to the top of the app level build.gradle file and do a clean and rebuild (according to https://codelabs.developers.google.com/codelabs/android-room-with-a-view/#6)

    In Android Studio, if you get errors when you paste code or during the build process, select Build >Clean Project. Then select Build > Rebuild Project, and then build again.


    UPDATE

    If you have migrated to androidx

    def room_version = "2.2.3" // check latest version from docs
    
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"
    

提交回复
热议问题