Android room persistent: AppDatabase_Impl does not exist

前端 未结 21 1396
日久生厌
日久生厌 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:35

    The question is pretty old, but I've stumbled on this today and none of the provided answers helped me. Finally I managed to resolve it by noticing that google documentation actually is still adopted to Java and not Kotlin by default, actually they have added a comment which I've ignored

    For Kotlin use kapt instead of annotationProcessor

    So, instead of

    annotationProcessor "androidx.room:room-compiler:$room_version"

    If you are developing with Kotlin, you should use:

        kapt "androidx.room:room-compiler:$room_version"
    
    0 讨论(0)
  • 2020-11-29 01:37

    if you are using kotlin classes to implement database then use

    apply plugin: 'kotlin-kapt'
    

    and

    kapt "android.arch.persistence.room:compiler:1.1.1"
    

    in your gradle file, it will work.

    0 讨论(0)
  • 2020-11-29 01:38

    Had the same problem. Implemented the few classes and interface as officially told in a new example project created by Android Studio: https://developer.android.com/training/data-storage/room/

    All mentioned solutions above did not help, the necessary _Impl files according to my database class were not generated by Room. Finally executing gradle clean build in terminal gave me the hint that lead to the solution:

    "warning: Schema export directory is not provided to the annotation processor so we cannot export the schema. You can either provide room.schemaLocation annotation processor argument OR set exportSchema to false."

    I added the parameter exportSchema = false in the database class

    @Database(entities = arrayOf(User::class), version = 1, exportSchema = false)
    abstract class AppDatabase : RoomDatabase() {
        abstract fun userDao(): UserDao
    }
    

    And then it worked, found these two generated files in the app module under generatedJava:

    • AppDatabase_Impl
    • UserDao_Impl

    I don't understand this behaviour as the parameter is said to be optional, see https://stackoverflow.com/a/44645943/3258117

    0 讨论(0)
  • 2020-11-29 01:39

    I met this problem because I have forgotten the apt dependences

    implementation "android.arch.lifecycle:extensions:$archLifecycleVersion"
    implementation "android.arch.persistence.room:runtime:$archRoomVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$archLifecycleVersion"
    annotationProcessor "android.arch.persistence.room:compiler:$archRoomVersion"
    

    after added the annotationProcessor, and rebuild it, the problem solved.

    0 讨论(0)
  • 2020-11-29 01:40

    Just use

    apply plugin: 'kotlin-kapt'
    

    in app build.gradle

    And keep both in dependencies

    annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
    kapt "android.arch.persistence.room:compiler:$rootProject.roomVersion"
    

    EDIT

    In newer version don't need to add both dependencies at a time Just use, hope it will work.

    kapt 'android.arch.persistence.room:compiler:1.1.1'
    
    0 讨论(0)
  • 2020-11-29 01:40

    The same phenomenon occurred to me.

    following

    implementation "android.arch.persistence.room:runtime:1.1.1"
    

    Adding causes another build error but tracks the cause from the log.

    In my case, there was an error in the SQL implementation. After fixing, the build was successful.

    So you may want to check the implementation of the entire room library instead of looking at the crashed locals.

    0 讨论(0)
提交回复
热议问题