In our app Koin overshadows actual crash log in Cr...
# koin
a
In our app Koin overshadows actual crash log in Crashlytics. Is there a solution to this. We get crash logs like this instead of actual crashes
Copy code
Caused by k.a.c.f.e: No definition found for '<package>.h' has been found. Check your module definitions.
       at org.koin.core.scope.Scope.findDefinition(Scope.java:52)
       at org.koin.core.scope.Scope.resolveInstance(Scope.java)
       at org.koin.core.scope.Scope.get(Scope.java:123)
       at org.koin.androidx.viewmodel.ViewModelResolutionKt$createViewModelProvider$1.create(ViewModelResolutionKt.java:25)
       at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:37)
       at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:23)
       at org.koin.androidx.viewmodel.ViewModelResolutionKt.getInstance(ViewModelResolutionKt.java:119)
       at org.koin.androidx.viewmodel.ViewModelResolutionKt.getViewModel(ViewModelResolutionKt.java:26)
This even happens in local testing
t
Why do you think this isn’t an actual crash? You have to figure out which view model is renamed to
<package>.h
and create a
viewModel<h> { h() }
provider.
a
It’s because we have been facing this from quite a while and app works in normal use cases. I am 100% sure its not actual crash. This reproduces every now and then in our local testing. Many times we have to resort to logs and breakpoints to fix simple crashes.
It started happening after we started loading our Koin modules in two steps.
t
If you load the modules in two steps, it sounds like a race-condition to me.
a
I think I figured out what was the issue. In our current implementation we are there are two type of modules 1. Authenticated which logged user can access 2. UnAuthenticated which are used for onboarding and such In our application class we load second type of modules. And first type of modules are loaded in home activity or deeplink entry points if and when user is logged in. Now after app crashes my guess is system tries to re-create previous activity (in some phones automatically in some after clicking on
Open App Again
) Since
Application
class only loads 2nd type of modules app crashes because there are no definitions available via
Koin
I have tested and confirmed this but now, what is the best way to do this. Currently I placed this in every Activity
Copy code
fun login() {
        try {
            loadKoinModules(listOf(authenticatedModules, authenticatedViewModels))
        } catch (e: DefinitionOverrideException) {
            // fail silently
        }
    }