Reputation: 939
I when try to implement a Room Database, I get the following error:
java.lang.RuntimeException: cannot find implementation for com.udacity.gradle.builditbigger.Database.HilarityUserDatabase. HilarityUserDatabase_Impl does not exist
at android.arch.persistence.room.Room.getGeneratedImplementation(Room.java:92)
I tried adding the relevant kotlin dependencies to my gradle file (shown below) but when I do, all of my Databinding classes that would normally be generated with any issues are now generating errors in my gradle console. Is there way for me to use the DataBinding library and the Room Pesistence Library?
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
...
dependencies{
kapt "android.arch.persistence.room:compiler:1.0.0"
}
Upvotes: 13
Views: 20502
Reputation: 1281
Add these Dependencies to your build.gradle file
implementation 'android.arch.persistence.room:runtime:1.1.1'
annotationProcessor 'android.arch.persistence.room:compiler:1.1.1'
kapt 'android.arch.persistence.room:compiler:1.1.1'
MhzDev answer is fine these are the updated version of the dependencies
Upvotes: 0
Reputation: 1
Had a similar problem while doing Codelabs. I was able to solve it by adding the updated Room dependencies on my build.gradle(module).
You can copy and paste the implementation declarations from the Room docs page in the Android Developer site. (Note: Check in your list of dependencies for
implementation 'androidx.room:room-runtime:2.2.5'
or similar, make sure to remove it and only leave the one you copied and pasted, which would look like this
implementation "androidx.room:room-runtime:$room_version"
)
Room | Android Developers #Declaring Dependencies
Upvotes: 0
Reputation: 91
I was facing the same issue, later found that I am not using the @Database annotation for AppDatabase
Use this
@Database(entities = {RowEntity.class, WifiDetailEntity.class}, version = 1)
public abstract class AppDatabase extends RoomDatabase
{ ...
Upvotes: 1
Reputation: 432
As explained above, for ease
1- Add the following in the build.gradle(Module:app) at the very top of the file
apply plugin: 'kotlin-kapt'
2- Then add
//Room for database
def room_version = "2.2.5"
implementation "androidx.room:room-runtime:$room_version"
implementation 'android.arch.persistence.room:runtime:1.1.1'
kapt 'android.arch.persistence.room:compiler:1.1.1'
3- Sync the file and clean the project. Done
Upvotes: 0
Reputation: 10529
For the newer version of the room compiler don't need to add both dependencies, Just do the following -
kapt 'android.arch.persistence.room:compiler:2.2.3'
Upvotes: 0
Reputation: 655
Make sure kotlin-kapt is included in app-level gradle file.
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
and make sure you use kapt instead of annotationProcessor. That solved my problem.
And also check Room Model, DAO, and Database files for @Entity, @Dao and @Database annotations.
Upvotes: 14
Reputation: 338
For usage of Room, LiveData and ViewModel you need these libraries:
•implementation "android.arch.persistence.room:runtime:1.0.0"
•implementation "android.arch.lifecycle:extensions:1.1.0"
•kapt "android.arch.persistence.room:compiler:1.0.0"
•kapt "android.arch.lifecycle:compiler:1.1.0"
LiveData and ViewModel allows you to use the DataBinding technique.
For more info check the official page: https://developer.android.com/topic/libraries/architecture/adding-components.html
Upvotes: 1
Reputation: 225
It did happen to me before, make sure that you have all 3 dependencies in build.gradle
implementation 'android.arch.persistence.room:runtime:1.0.0'
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0'
kapt 'android.arch.persistence.room:compiler:1.0.0'
Also, a "Project Clean" after gradle synch will help as well.
Upvotes: 22