user9824289
user9824289

Reputation:

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?

Upvotes: 31

Views: 23541

Answers (5)

B Wray
B Wray

Reputation: 379

If you're using Kotlin, as of Sep 2023, ksp has replaced kapt and is supported by Room.

https://developer.android.com/build/migrate-to-ksp

Top-level build file - build.gradle.kts (MyProject)

plugins {
    ...
    id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false
}

Project-level build file - build.gradle.kts (:app)

plugins {
    ...
    id("com.google.devtools.ksp")
}
...
dependencies {
    ...
    val roomVersion = "2.5.2"
    implementation("androidx.room:room-runtime:$roomVersion")
    ksp("androidx.room:room-compiler:$roomVersion")
    ksp("androidx.lifecycle:lifecycle-common:2.6.2")
}

Upvotes: 0

Moataz
Moataz

Reputation: 657

this only worked for me

    kapt "androidx.room:room-compiler:2.5.0-alpha03"

and all dependencies will be

id 'kotlin-kapt'


// Room Database
def room_version = "2.4.3"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:2.5.0-alpha03"

Upvotes: 0

Sheikh Nazar
Sheikh Nazar

Reputation: 1

My error was

java.lang.RuntimeException: cannot find implementation for
    com.template.database.MoneyDatabase. MoneyDatabase_Impl does not exist.

I solved this by adding

@Database(entities = {Coins.class},version = 1,exportSchema = false)

above the database class.

Upvotes: 0

fmag
fmag

Reputation: 123

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'

Upvotes: 1

EpicPandaForce
EpicPandaForce

Reputation: 81539

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"

Upvotes: 73

Related Questions