Closed Cuyer closed 2 weeks ago
You initializing Koin inside onCreate in Activity, which is recreated on theme change. Try to initialize it inside onCreate in Application.
I've tried it as such:
class MainApp : Application() {
override fun onCreate() {
super.onCreate()
startKoin {
androidContext(this@MainApp)
modules(
appModule(),
androidModule()
)
logger(PrintLogger())
}
}
}
But I get error java.lang.IllegalStateException: KoinApplication has not been started
Interesting. What are you doing to get this exception? I remember that I encountered this error on first inject call in my pet project when I forgot to register my application class in Manifest file.
Yes, that's exactly the issue. I had to register application class in manifest file and everything works now. And I've checked and after chaning theme the app doesn't crash. Thank You!
Omg I have the same problem, I do initKoin() in Common Main:
@Composable
internal fun App() {
AppTheme {
initKoin()
Napier.base(DebugAntilog())
Navigator(screen = FirstScreen)
}
}
fun initKoin() = startKoin {
modules(
sharedViewModelModule,
LoginViewModelModule,
SettingsValueModule,
)
}
and my application crashes already when switching themes using the theme switch button in the status bar.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Describe the bug When changing from light to dark theme or vice versa, following error is thrown:
KoinAppAlreadyStartedException: A Koin Application has already been started
To Reproduce Steps to reproduce the behavior:
Expected behavior App doesn't crash
Koin module and version: I suppose its koin-compose:3.6.0-wasm-alpha2
I am working on a project that uses compose multiplatform. I've tried using documentation to start koin, but its lacking information regarding compose multiplatform.
Snippet or Sample project to help reproduce