Deep Naik
05/15/2025, 5:06 PMSeri
05/15/2025, 5:52 PMSeri
05/15/2025, 5:53 PMDeep Naik
05/16/2025, 1:38 AMSeri
05/16/2025, 2:51 PMRoomDatabase.Builder<AppDatabase>
, sure. If you want to avoid that, you'll need to create your RoomDatabase.Builder<AppDatabase>
with a Context
closer to your application layer and then use dependency injection to bring it into the :data moduleDeep Naik
05/19/2025, 5:03 AMTim Karagosian
05/25/2025, 1:29 PMval myDao = getDatabase(applicationContext).myDao()
And this is in its own class on Android native to build the db correctly with application context passed in via main activity:
fun getDatabase(context: Context): MyDatabase{
val dbFile = context.getDatabasePath("my_db.db")
return Room
.databaseBuilder<MyDatabase>(
context = context.applicationContext,
name = dbFile.absolutePath,
)
.setDriver(BundledSQLiteDriver())
.fallbackToDestructiveMigrationOnDowngrade()
.fallbackToDestructiveMigration()
//.enableMultiInstanceInvalidation()
//.addMigrations(MIGRATION_1_2)
.build()
}