-
-
Notifications
You must be signed in to change notification settings - Fork 710
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
No definition found for class:'androidx.lifecycle.SavedStateHandle' #963
Comments
Hi, already resolved this issue, but with weird solution. Before in module was like this, all values in ViewModel constructor was passed by name Now I changed by order And all works well. Not sure what caused this issue, this all really very weird. |
same here with @OleksandrGrument |
can be a problem with new default ViewModel factory 🤔 |
it's curious that it's looking for
|
The same problem happened to me using version 2.2.2. The only way I could make it work is by changing the ViewModel constructor params order to have the Obviously it took me some hours to figure it out 😱 |
I also get the And passing the parameters by name or by position does not fix it either. |
I have also noticed I am not able to add the state parameter when calling |
@jsaumellbasetis I'm using |
Ok sorry, I got it. I had spent several hours on this, and half an hour after writing I see that I did not have the androidx-fragment koin library, and I had the android-viewmodel instead of androix-viewmodel. |
Similar problem if the savedStateHandle parameter is not the first. |
I saw in other issues messages about stateViewModel/sharedStateViewModel is it deprecated or i'm looking not at the right place? ViewModel
Delegate to share viewmodel. It seems I need something like getKoin().getStateViewModel but it's not in the library anymore.
And usage
Any thoughts how to combine sharedGraphViewModel and SavedStateHandle? |
It seems I figurre it out. Please have a look at this gist if some one needs the same functionality |
This solved my issue https://stackoverflow.com/a/61316807/7046279 |
The problem is at
where the cause is E.g. the wrong factory will be chosen if the @arnaudgiuliani is it an expected behavior(therefore a bug in the documentation) or a bug? |
I'm on
|
Also I found another weird behaviour. The order of parameters may cause this bug. When the "state" 1 or 2 in order, all working properly, but when state is as 4 by order getting this error. |
I've also encountered this issue. Was working okay on
|
@TepesLucian Thanks. Also you can use |
This is the signature of the class QuizViewModel(
savedStateHandle: SavedStateHandle,
quizId: String,
cardId: String,
context: Context,
service: Service,
) : ViewModel() and I defined the module {
viewModel { (quizId: String, cardId: String) ->
QuizViewModel(get(), quizId, cardId, get(), get())
} and consumed it like so: val viewModel by viewModel<QuizViewModel>(state = emptyState()) {
parametersOf("some id", "another id")
}
…without using the |
@TepesLucian @ALXKAY @c-b-h Doesn't passing I also suppose the bug in 2.2.2 deserves a thread of its own. |
@gmk57 not really since you can use that bundle to apply initial params to |
The documentation is also not clear that |
Koin 3.0.1 makes parameters available in the Koin graph. This means that we can resolve anything with |
StateViewModel API has been restored in 3.0.1, with consistent factory resolution. |
@arnaudgiuliani How do we do that in |
@sagarpatel288 no, just use |
@arnaudgiuliani Thanks for the quick reply. It says Here are the details: Classpath
Plugin
Dependencies
Module
ViewModel
Service class
Usage in the service class
Confirmed the Import statement in the service class |
The current solution is inspired from here: https://insert-koin.io/docs/reference/koin-core/injection-parameters/ Module
Usage in the service class
I hope I am using it properly. Looking for a better way though. |
The usage is not good. It should be |
Yeah... How can I solve "unresolved reference" while trying to use |
if you gradle config is good, be sure to make the import for extension function. |
Below import is there but it is not being used even when I use
|
I m facing this issue while injecting a ViewModel having SavedStateHandle as one of the constructor parameter. Setup:
Module:
Composable:
ViewModel:
I m using Dependencies in build.gradle:
|
@SameerShelarr I have downgraded the koin_version to |
Hi. I'm seeing this same issue reported in
|
I'm using new Koin version 2.2.1 and I'm getting runtime error in viewmodel where i'm using SavedStateHandle
In previous version 2.1.6 all was fine. I used savedStateViewModel, now i'm getting crash after migration
all I did acording to article, maybe something are missed there?
https://doc.insert-koin.io/#/koin-android/viewmodel?id=viewmodel-and-state-bundle
Caused by: org.koin.core.error.NoBeanDefFoundException: No definition found for class:'androidx.lifecycle.SavedStateHandle'. Check your definitions! at org.koin.core.scope.Scope.throwDefinitionNotFound(Scope.kt:282) at org.koin.core.scope.Scope.resolveInstance(Scope.kt:251) at org.koin.core.scope.Scope.get(Scope.kt:204) at com.grument.laika.di.DiManager$module$1$19.invoke(DiManager.kt:76) at com.grument.laika.di.DiManager$module$1$19.invoke(DiManager.kt:35) at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53) at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:36) at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:103) at org.koin.core.scope.Scope.resolveInstance(Scope.kt:236) at org.koin.core.scope.Scope.get(Scope.kt:204) at org.koin.androidx.viewmodel.factory.StateViewModelFactory.create(StateViewModelFactory.kt:21) at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:69) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) at org.koin.androidx.viewmodel.ViewModelResolverKt.get(ViewModelResolver.kt:23) at org.koin.androidx.viewmodel.ViewModelResolverKt.resolveInstance(ViewModelResolver.kt:12) at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:86) at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:72) at org.koin.androidx.viewmodel.koin.KoinExtKt.getViewModel(KoinExt.kt:41) at org.koin.androidx.viewmodel.ext.android.FragmentExtKt.getViewModel(FragmentExt.kt:71) at com.grument.laika.view.transfer.StyleTransferFragment$$special$$inlined$viewModel$2.invoke(FragmentExt.kt:73) at com.grument.laika.view.transfer.StyleTransferFragment$$special$$inlined$viewModel$2.invoke(Unknown Source:0) at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81) at com.grument.laika.view.transfer.StyleTransferFragment.getViewModel(Unknown Source:2) at com.grument.laika.view.transfer.StyleTransferFragment.initObservers(StyleTransferFragment.kt:101) at com.grument.laika.view.transfer.StyleTransferFragment.onViewCreated(StyleTransferFragment.kt:42) at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:332) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1199) at androidx.fragment.app.FragmentManager.addAddedFragments(FragmentManager.java:2236) at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2009) at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1965) at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1861) at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:223) at android.app.ActivityThread.main(ActivityThread.java:7656) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
in module
viewModel { (image: File) -> StyleTransferViewModel(context = androidContext(), repository = get(), modelManager = get(), state = get(), image = image) }
the class where i'm injecting
class StyleTransferViewModel(private val context: Context, private val repository: Repository, private val modelManager: ModelManager, state: SavedStateHandle, image: File) : CommonViewModel(repository)
in fragment
private val viewModel: StyleTransferViewModel by viewModel{ parametersOf(args.image) }
Koin project used and used version (please complete the following information):
[e.g]:
koin-core version 2.2.1
Any help apreciated
The text was updated successfully, but these errors were encountered: