Home > database >  Cannot find implementation Room database
Cannot find implementation Room database

Time:04-28

I have created a module and using room DB in that module.

I am using this module as an generated release aar. When it goes for the creation of database I get the following exception

java.lang.RuntimeException: cannot find implementation for com.internals.UserDatabase.UserDatabase_Impl  does not exist
    at androidx.room.Room.getGeneratedImplementation(Room.java:100)
    at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1486)
    at a.a.a.e.a.<init>(Unknown Source:17)

In the app level build gradle

def room_version = "2.4.2"
implementation "androidx.room:room-ktx:$room_version"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

Have also added proguard rule for room

-keep class * extends androidx.room.RoomDatabase
-keep class * extends androidx.room.Entity

CodePudding user response:

kapt is for Kotlin.

First, add:

annotationProcessor "android.arch.persistence.room:compiler:1.0.0"

to your dependencies closure.

Then, upgrade android.arch.persistence.room:rxjava2 and android.arch.persistence.room:testing to 1.0.0 instead of 1.0.0-rc1.

ref: https://developer.android.com/jetpack/androidx/releases/room

CodePudding user response:

//Room: https://developer.android.com/topic/libraries/architecture/room
    def room_version = "2.4.2"
    implementation "androidx.room:room-runtime:$room_version"
    //annotationProcessor "androidx.room:room-compiler:$room_version" // For Kotlin use kapt instead of annotationProcessor
    kapt "androidx.room:room-compiler:$room_version"
    // optional - Kotlin Extensions and Coroutines support for Room
    implementation "androidx.room:room-ktx:$room_version"
    // optional - RxJava support for Room
    implementation "androidx.room:room-rxjava2:$room_version"
    // optional - Guava support for Room, including Optional and ListenableFuture
    implementation "androidx.room:room-guava:$room_version"
    // Test helpers
    testImplementation "androidx.room:room-testing:$room_version"
  • Related