class file for androidx.room.RoomDatabase not found when trying to use Hilt with Roomdb

This is the error message I am getting. I checked the web and I have every dependency needed, I setup everything correctly. The problem is that I already have this setup on another project which is working fine, for some reason tho it’s not working here. I tried invalidating caches, restarting and such but nothing has bore fruit. I am super confused as to what is causing this.

error: cannot access RoomDatabase
    return DatabaseModule_ProvideAppRepositoryFactory.provideAppRepository(databaseModule, appDatabase(), ApplicationContextModule_ProvideContextFactory.provideContext(applicationContextModule));
                                                                          ^
  class file for androidx.room.RoomDatabase not found
1 error

This is the database module

@Module
@InstallIn(SingletonComponent::class)
class DatabaseModule {
    @Provides
    @Singleton
    fun provideAppDatabase(@ApplicationContext context: Context): AppDatabase {
        return Room.databaseBuilder(
            context,
            AppDatabase::class.java, "app-db"
        ).build()
    }

    @Provides
    fun provideAppRepository(
        db: AppDatabase,
        @ApplicationContext ctx : Context
    ): AppRepository {
        return AppRepository(db, ctx)
    }

These are my dependencies alongide Kotlin Kapt

Plugins{
    id(GradlePluginId.ANDROID_LIBRARY)
    id(GradlePluginId.KOTLIN_ANDROID)
    id(GradlePluginId.KOTLIN_KAPT)
    id(GradlePluginId.HILT_ANDROID)
}
...

  implementation(LibraryDependency.ROOM)
    implementation(LibraryDependency.ROOM_KTX)
    kapt(LibraryDependency.ROOM_COMPILER)

Which is this 2.2.6 version, but i've been using the "2.3.0-beta02" as well
    const val ROOM = "androidx.room:room-runtime:${LibraryVersion.ROOM}"
    const val ROOM_COMPILER = "androidx.room:room-compiler:${LibraryVersion.ROOM}"
    const val ROOM_KTX = "androidx.room:room-ktx:${LibraryVersion.ROOM}"
@Database(entities = [CBImageDataModel::class], version = 1)
abstract class AppDatabase : RoomDatabase() {
    abstract fun imageDao(): ImageDao
}

@Entity(tableName = "images")
@TypeConverters(ImageTypeConverters::class)
data class CBImageDataModel(
    @PrimaryKey(autoGenerate = true) val id: Long? = null,
    @ColumnInfo(name = "server_id") val serverID: Int
)

class AppRepository @Inject constructor(private val db: AppDatabase, private val context: Context) { ... 

Source: Android Questions

One Reply to “class file for androidx.room.RoomDatabase not found when trying to use Hilt with Roomdb”

LEAVE A COMMENT