Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koin crash randomly on minified app while trying to create a SavedStateHandle #1625

Closed
florent37 opened this issue Jul 26, 2023 · 12 comments
Closed
Labels
status:checking currently in analysis - discussion or need more detailed specs type:issue viewmodel
Milestone

Comments

@florent37
Copy link

florent37 commented Jul 26, 2023

Describe the bug

Koin crash randomly on minified app while trying to create a SavedStateHandle then inject it into a viewmodel

Caused by os0.b
No definition found for class:'androidx.lifecycle.i0' q:''. Check your definitions!
org.koin.core.scope.Scope.throwDefinitionNotFound (Scope.kt:304)
org.koin.core.scope.Scope.resolveValue (Scope.kt:274)
org.koin.core.scope.Scope.resolveInstance (Scope.kt:231)
org.koin.core.scope.Scope.get (Scope.kt:210)
my.package.di.TimelineModuleKt$timelineModule$1$invoke$$inlined$viewModelOf$1.invoke (KoinExt.kt:93)
my.package.di.TimelineModuleKt$timelineModule$1$invoke$$inlined$viewModelOf$1.invoke (KoinExt.kt:38)
org.koin.core.instance.InstanceFactory.create (InstanceFactory.kt:51)
org.koin.core.instance.FactoryInstanceFactory.get (FactoryInstanceFactory.kt:38)
org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core (InstanceRegistry.java:116)
org.koin.core.scope.Scope.resolveValue (Scope.kt:246)
org.koin.core.scope.Scope.resolveInstance (Scope.kt:231)
org.koin.core.scope.Scope.get (Scope.kt:210)
org.koin.androidx.viewmodel.factory.KoinViewModelFactory.create (KoinViewModelFactory.kt:25)
androidx.lifecycle.ViewModelProvider.get (ViewModelProvider.kt:187)
androidx.lifecycle.ViewModelProvider.get (ViewModelProvider.kt:153)
org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel (GetViewModel.kt:44)
my.package.TimelineKt.TimelineScreen (Timeline.kt:302)
my.package.TimelineKt$Timeline$2$1.invoke (Timeline.kt:78)
my.package.TimelineKt$Timeline$2$1.invoke (Timeline.kt:77)
androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.jvm.kt:116)
androidx.compose.runtime.internal.ComposableLambdaImpl.invoke (ComposableLambda.jvm.kt:34)

and the class looks like this :

internal class TimelineViewModel(
      savedStateHandle: SavedStateHandle,
      private val useCase1: UseCase1,
      private val useCase2: UseCase2,
)

we're using the constructor syntax in our koin module definition

val timelineModule = module {
      viewModelOf(::TimelineViewModel)
}

It's not reproductible easily, we did not succeed to have this while testing on our devices

Koin project used and used version (please complete the following information):

  • koin-core version 3.4.2
  • koin-android version 3.4.2
@Beb3r
Copy link

Beb3r commented Jul 26, 2023

+1
Also experiencing the issue on prod randomly

@milicasiriski
Copy link

+1

@arnaudgiuliani arnaudgiuliani added viewmodel type:issue status:checking currently in analysis - discussion or need more detailed specs labels Aug 4, 2023
@arnaudgiuliani arnaudgiuliani added this to the android-3.5.0 milestone Aug 4, 2023
@arnaudgiuliani
Copy link
Member

we need a way to reproduce this case 🤔

@arnaudgiuliani
Copy link
Member

any better with 3.4.3 update? I know that 3.4.2 had maven metadata issues ... not sure it's any related

@milicasiriski
Copy link

It works for me on 3.4.3 🎉

@okycelt
Copy link

okycelt commented Aug 24, 2023

We're still seeing this with 3.4.3 (and koin compose 3.4.6), but subjectively it seems less frequent than with 3.4.0 (and koin compose 3.4.3).

For us, it also happens randomly during development. We tried to isolate the issue, but weren't able to reliably reproduce.

@arnaudgiuliani
Copy link
Member

how complex is the arguments passed in the SSH?

@okycelt
Copy link

okycelt commented Aug 29, 2023

how complex is the arguments passed in the SSH?

We never pass complex arguments to SSH, the most complex SSH contains one Long and one String.

@arnaudgiuliani
Copy link
Member

Ok, nothing strong.

There can be a side effect, observed at #1561

@okycelt
Copy link

okycelt commented Aug 30, 2023

Maybe I'm missing something, but shouldn't getViewModel() in compose always be called from the main thread? If so, I'm not sure how we could call it from different threads.

@Composable
fun SomeScreen(viewModel: SomeViewModel = getViewModel()) {
    //
}

@arnaudgiuliani
Copy link
Member

yes, it should be kept on the main thread. If you can in a way have a sample to reproduce, I will be happy to investigate 👍

@arnaudgiuliani
Copy link
Member

let's see with koin-android 3.5.0 and parameter race condition fix how it goes :+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:checking currently in analysis - discussion or need more detailed specs type:issue viewmodel
Projects
None yet
Development

No branches or pull requests

5 participants