2

I was developing an app where I try to implement a SQLDelight database, in order to I have to create a internal actual function where I keep the cache of the app.

But my problems cames when I try to configurate to AndroidMain module, due to the context is needed.

The code of my cache class in my androidMain is the following:

internal actual fun cache(): RickMortyDatabase {
    val driver = AndroidSqliteDriver(RickMortyDatabase.Schema, AppContext().context, "characters.db")
    return RickMortyDatabase(driver)
}

actual class AppContext actual constructor() {
    lateinit var context: Context
        private set

    constructor(context: Context) : this() {
        this.context = context
    }
}

So how should I initialize the context pass to AndroidDriver?? becasuse as I'm doing, it's not working, and there's no way to recover context from androidMain module.

If you know come working solution, and can share, take thanks in advance !

Manuel Lucas
  • 636
  • 6
  • 17

0 Answers0