-
-
Notifications
You must be signed in to change notification settings - Fork 732
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-android-compose] Broken view model factory when migrating from 3.5.0 -> 3.5.3/3.5.4 #1844
Comments
Can you detail it a bit more? |
Thanks @arnaudgiuliani ! Sure, The issue just affects when the
And this is the invocation on the Test Class:
The first TestCase works fine, but the second one fails on this. It happens to all the Test Classes. It was working fine until now. Thanks in advance |
@arnaudgiuliani Do you have any updates regarding this issue? Our tests are also affected by the same issue, therefore we're currently not able to update the koin version. |
Hi @arnaudgiuliani, any update about this issue? Thanks in advance |
weird, seems that VM factory is invoked after scope closing 🤔 |
can anyone help by providing a test project for that? @kasim-canol-sz @javiercamarenatriguero |
We are experiencing this after upgrading too. Did anyone find a workaround? |
I've the exact same issue. I can work on a small test project if it is necessary, but the issue is present in one of my OSS project (https://github.com/GerardPaligot/conferences4hall/tree/test/schedules). In this project, I'm using koin These two classes is using @get:Rule
val koinTestRule = KoinTestRule.create {
androidContext(InstrumentationRegistry.getInstrumentation().targetContext.applicationContext)
modules(listOf(scheduleModule, instrumentedModule))
} If I'm executing one by one test classes, there is no issue but if I'm merging these test classes in only one file or if I'm executing these classes in the same JVM (run at the package level), I got the error: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:590)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
... 1 more
Caused by: org.koin.core.error.ClosedScopeException: Scope '_root_' is closed
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:224)
at org.koin.core.scope.Scope.get(Scope.kt:213)
at org.koin.androidx.viewmodel.factory.KoinViewModelFactory.create(KoinViewModelFactory.kt:25)
at androidx.lifecycle.ViewModelProvider$Factory.create(ViewModelProvider.android.kt:158)
at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release(ViewModelProviderImpl.kt:67)
at androidx.lifecycle.viewmodel.ViewModelProviderImpl.getViewModel$lifecycle_viewmodel_release$default(ViewModelProviderImpl.kt:47)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:91)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.android.kt:109)
at org.koin.androidx.viewmodel.GetViewModelKt.resolveViewModel(GetViewModel.kt:44)
at org.gdglille.devfest.android.theme.m3.schedules.feature.ScheduleGridVMKt.ScheduleGridVM(ScheduleGridVM.kt:82)
at org.gdglille.devfest.android.theme.m3.schedules.feature.ScheduleGridAdaptiveKt$ScheduleGridAdaptive$1.invoke(ScheduleGridAdaptive.kt:39)
at org.gdglille.devfest.android.theme.m3.schedules.feature.ScheduleGridAdaptiveKt$ScheduleGridAdaptive$1.invoke(ScheduleGridAdaptive.kt:38) It starts from I hope it can help. Available to carry out further investigations. |
After some deeper investigations, it seems that I don't have a fix but if you need a workaround, you can force the correct scope inside your viewModel: ScheduleGridViewModel = koinViewModel(
scope = KoinPlatformTools.defaultContext().get().scopeRegistry.rootScope
) or use setContent {
KoinContext(context = KoinPlatformTools.defaultContext().get()) {
// Your composable tree
}
} I hope it can help someone here! |
Hi there, after applying the given solution (setting the scope) it still fails on the second test:
Hope it could help to find a solution. |
Ok, let me check it again. I missed the issue 👍 |
Seems linked to recent |
let's follow up #1900 - Fix around base Scope API and Local Composition should do the thing. |
Describe the bug
I recently upgraded to koin-androidx-compose:3.5.4 from koin-androidx-compose:3.5.0 and the Automation Test stat failing because of this error:
Tested it just affect to
koin-android-compose
library as the rest of koin libraries are not affecting the Android Test results.To Reproduce
Steps to reproduce the behavior:
Expected behavior
It should not fail as v3.5.0 version.
Koin module and version:
koin-androidx-compose:3.5.3
&koin-androidx-compose:3.5.4
The text was updated successfully, but these errors were encountered: