scenarios When Trying to Use Room Database with Coroutines in Android 12: 'Database is not open'
I'm prototyping a solution and I'm relatively new to this, so bear with me. I'm working with an scenario when trying to perform database operations using Room with Kotlin Coroutines in my Android application targeting Android 12. The behavior message I receive is `Database is not open`. I've set up my Room database like this: ```kotlin @Database(entities = [User::class], version = 1) abstract class AppDatabase : RoomDatabase() { abstract fun userDao(): UserDao() } val db = Room.databaseBuilder( applicationContext, AppDatabase::class.java, "app-database" ).build() ``` When I try to access the database in a coroutine like so: ```kotlin fun insertUser(user: User) { GlobalScope.launch(Dispatchers.IO) { db.userDao().insert(user) } } ``` I get the aforementioned behavior. I've confirmed that the `db` variable is not `null`, but it seems like the database is not being initialized properly before the insert operation is called. I've tried moving the database initialization to the `onCreate` method of my Application class, but the scenario continues. Additionally, I checked that my `UserDao` interface is correctly annotated with `@Insert`. Could this be related to the lifecycle of the database or the coroutine scope I'm using? Are there any best practices for using Room with coroutines that I might be missing? Any help would be greatly appreciated! I'm working on a CLI tool that needs to handle this. Any ideas what could be causing this? I'm working with Kotlin in a Docker container on macOS. Any help would be greatly appreciated! Is there a better approach?