I’m facing this crash starting the app i’m developing:
java.lang.ExceptionInInitializerError
at com.innopro.b4work.newcode.di.ModulesKt.getDataModule(Modules.kt:74)
Caused by: org.koin.core.error.DefinitionOverrideException: Definition '[Single:'com.innopro.b4work.data.redux.analytics.FirebaseTracker']' try to override existing definition. Please use override option to fix it
when adding AvatarViewModel in a preexistent module
val profileModule = module {
... // Other modules and factories
factory { (ui: ProfileFullPresenter.Contract) -> ProfileFullPresenter(ui, get(), get(), get()) }
viewModel { AvatarViewModel(repository = get()) }
}
This presenter (ProfileFullPresenter) uses the same repository (PhotoRepository, who only has one implementation class (PhotoNetworkRepository) as a constructor dependency. So I thought to use get like the presenter does. But the crash is happening if I add my viewmodel declaration, not if I remove it.
This repository dependency is declared in another module:
val repositoryModule = module {
... // Other repositories
factory { PhotoNetworkRepository(get()) }
}
It has a dependency (ApiService) declared in this module:
val dataModule = module {
… // Other dependencies
factory { PhotoApi.create() }
}
But according to the stacktrace it complains about that bean:
val analyticsModule = module {
single { FirebaseTracker() }
single { get<FirebaseTracker>() }
single { AnalyticsPresenter(get()) }
}
I cannot understand the relationship between the error message and my viewmodel because it does not use this dependency and not also it’s dependencies declared in it’s constructor
All modules are declared inside startKoin function
modules(
// more modules
profileModule,
// more modules
dataModule,
analyticsModule,
repositoryModule,
// more modules
)