I'm getting a
ViewModel has no zero argument constructor
error when trying to construct a hilt view model in a compose function. Anyone else experiencing this? I'm not using the jetpack navigation component, just trying to inject a view model scoped to LocalViewModelStoreOwner.current. I get this error when trying to inject even a simple class with no sub-dependencies.
My view model is provided like this:
viewModel: MyViewModel = viewModel()
, and I'm using the @HiltViewModel annotation on my view model. My activity and application all support hilt injection properly. I'm using the "androidx.lifecycle:lifecycle-viewmodel-compose" dependency for creating my view model. Let me know if you need more information.
Edit: this also only happens when trying to create the view model with any injected dependencies. If the view model has no dependencies, it works fine. The
hiltViewModel()
is only supposed to be used with the navigation component, which I am not using. I am using an alternate navigation library (this one:
https://github.com/olshevski/compose-navigation-reimagined), but from my understanding, it sets the LocalViewModelStoreOwner properly, and that's what the
viewModel()
function uses. I'm assuming it's something to do with the view model factory.