I am writing my first application with Room. I discovered it has issues when it uses kotlin, even some sample doesn't work on my machine, so I rollback to plain Java.
FilmsDatabaseJ db = Room.databaseBuilder(getApplicationContext(), FilmsDatabase.class, "DATABASE_NAME").build();
This call fails with exception:
java.lang.RuntimeException: cannot find implementation for com.home.myapplication.films.storage.FilmsDatabase. FilmsDatabase_Impl does not exist
I explored source code, Room expects to have such class already (does generated somewhere?), but by some reason such class doesn't exist for my case which is not far from documentation. Could you please share your ideas what might went wrong here?
@TypeConverters({Converters.class})
@Database(entities = {Film.class, User.class, UserFilms.class}, version = 1)
public abstract class FilmsDatabaseJ extends RoomDatabase {
private static final String DATABASE_NAME = "DATABASE_NAME";
private static FilmsDatabaseJ instance;
public abstract FilmsDaoJ getFilmsDao();
@NotNull
public static FilmsDatabaseJ getInstance(Context context) {
if (instance == null) {
synchronized (FilmsDatabaseJ.class) {
if (instance != null) return
instance = Room.databaseBuilder(context, FilmsDatabaseJ.class, DATABASE_NAME).build();
}
}
return instance;
}
}
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"
// Room (use 1.1.0-beta2 for latest beta)
implementation "android.arch.persistence.room:runtime:1.0.0"
annotationProcessor "android.arch.persistence.room:compiler:1.0.0"
This is because the kotlin compiler doesn't work well with @Database java annotation (which generates the FilmsDatabase_Impl
for you).
So to fix this:
First you need to get the kapt
plugin to parse annotation in kotlin file, add this to your app level gradle:
apply plugin: 'kotlin-kapt'
Then replace annotationProcessor
with kapt
for the Room's compiler
kapt "android.arch.persistence.room:compiler:1.0.0"
Compiling the project again now you should see those boiler plate codes get generated and resolve the above error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With