I can see following crashes in the app. I got the ...
# koin
k
I can see following crashes in the app. I got the code from the official Koin samples repo. any ideas? Error:
Fatal Exception: java.lang.IllegalStateException
Koin context has not been initialized in rememberKoinApplication
Code:
import android.app.Application
class MainApplication : Application() {
override fun onCreate() {
super.onCreate()
instance = this
}
companion object {
var instance : Application? = null
}
}
I suspect the app is in background when this crash occurs. It is happening on One Plus device only though.
k
Yes, it's there. This issue is happening probably when the app is in background and not all the time. I suspect it is something to do with this way of providing application context. IS there any better way to do this?
Copy code
override fun onCreate() {
    super.onCreate()
    instance = this
}

companion object {
    var instance : Application? = null
}
a
I'm working on something better to help for such case
🙏 1
k
Looking forward. To it
👍 1
a
@Karan Sharma @arnaud.giuliani Any solution to this? I am facing the exact same issue. Fatal Exception: java.lang.IllegalStateException Koin context has not been initialized in rememberKoinApplication Although my crashlytics marks it as a fatalError, Surprisingly it doesn't crashes the application. The way I am initializing koin in my common App.kt file is as follows
Copy code
fun App(
    prefs: DataStore<Preferences>,
    onAppStateChanged: (AppState) -> Unit = {}
) {
    MaterialTheme(colorScheme = LIGHT_COLOR_SCHEME) {
        KoinApplication(
            application = {
                modules(
                    module {
                        single<DataStore<Preferences>> { prefs }
                    } + appModules
                )
            }
        ) {
👍 2
a
you need to setup an android context at start
in your section:
Copy code
KoinApplication(
            application = {