简体   繁体   中英

Room + cannot find implementation DB + DB_Impl does not exist

I am getting following error while running application

java.lang.RuntimeException: cannot find implementation for com.abc.db.abdDB. abcDB_Impl does not exist

My build.gradle has following configuration:

implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"
annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0-alpha1"
implementation "androidx.room:room-runtime:2.0.0-alpha1"
annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"

My Database class:

fun getDatabase(context: Context): abcDB? {
        if (dbInstance == null) {
            synchronized(abcDB::class.java) {
                if (dbInstance == null) {
                    dbInstance = Room.databaseBuilder(context.applicationContext,
                            abcDB::class.java, "abc_db")
                            .fallbackToDestructiveMigration()
                            .addCallback(sRoomDatabaseCallback)
                            .build()
                }
            }
        }
        return dbInstance
    }

Does anyone try to use androidX API? Can someone help to find solution for this?

If you use Kotlin, then you have to use kapt instead of annotationProcessor , and must also apply kotlin-kapt plugin.

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

dependencies {
    implementation "androidx.lifecycle:lifecycle-extensions:2.0.0-alpha1"
    kapt "androidx.lifecycle:lifecycle-compiler:2.0.0-alpha1"
    implementation "androidx.room:room-runtime:2.0.0-alpha1"
    kapt "androidx.room:room-compiler:2.0.0-alpha1"

For Java

in app build.gradle

use

implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM