30

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?

  • See a [possible answer here in this post](https://stackoverflow.com/questions/47274677/room-cannot-find-implementation/53669919#53669919): – Ráfagan Dec 07 '18 at 19:09

4 Answers4

71

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"
EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
  • 5
    thanks - adding `kotlin-kapt` worked for me (I had already put `kapt` on the dependencies), but isn't it weird that the build process wouldn't flag up that there isn't a plugin to handle the `kapt` statements – kassim Aug 05 '18 at 13:37
1

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'
fmag
  • 129
  • 1
  • 7
  • 2
    This information is very old and outdated. – Bink Jan 22 '21 at 22:57
  • 2
    @Bink since you didn't bother on suggesting an improvement, I can do it for you. What you should do is use the following instead of the above: `implementation "androidx.room:room-runtime:$room_version"` `annotationProcessor "androidx.room:room-compiler:$room_version"` $room_version is dependent on latest version released by Google – user3170251 Mar 22 '21 at 20:23
0

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.

Scott Stanchfield
  • 29,742
  • 9
  • 47
  • 65
  • 1
    This didn't work for me - the issue I believe was `annotationProcessor "androidx.room:room-compiler:2.0.0-alpha1"` should be `kapt "androidx.room:room-compiler:2.0.0-alpha1" ` – Zain Jul 06 '22 at 21:49
0

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"
Moataz
  • 495
  • 3
  • 20