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
viewModel() not resolving #383
Comments
Hey, did you registered your |
Having the same issue here. I did some investigation, and it's most likely related to the ViewModel class being on different packages. |
You should list your imports. You should import the viewModel extenion funciton for injection, not the viewModel definition dsl. |
Hi thanks for the response. I checked the libraries and managed to find out the package structure. Oddly, the import is ignored by the declaration of "viewModel". As I said, it might be related to the expected parameter being on a different package. I'll give it some further investigation to have a better comprehension. |
After some deep investigation I was able to find the source of the issue. The extension function "viewModel" is meant to be an extension of the androidx.lifecycle.LifecycleOwner which is an interface implemented by the class ComponentActivity when using androidx (just out of curiosity, it's SupportActivity for the support version of libs, which is fine). So, the Koin implementation is actually correct for androidx:core on version 1.0.1 (latest stable version). However on version 1.1-alpha the interface LifecycleOwner is not implemented anymore. It could be a temporary issue because it's still on alpha. All in all, for those who had this issue using the alpha version suggested by Android Studio, just downgrade it to version 1.0.1 and it will work fine:
@noman87 could you try it? |
As @xyzwilliamxyz mentioned, ComponentActivity implementation was changed from android.core:core:1.1.0-alpha0x. So I changed androidx core library to 1.0.1 and koin libraries to 1.0.2 not latest 2.0.0-rc-2. Then it worked. |
Since androidx.core:1.1.0-alpha0x, there are two ComponentActivity classes in androidx.core and androidx.activity packages. |
So how to config koin 2.0 to work with androidx viewmodel? I have tried lower version androidx to latest stable 1.0.2 but did not work |
I have the same issue with the viewmodel from androidx.lifecycle:lifecycle-viewmodel:2.0.0@aar and the Koin injection from org.koin:koin-androidx-viewmodel:2.0.1 with by viewModel() (not resolving). |
Did you try to import "org.koin.android.viewmodel.ext.android.viewModel" manually? |
FYI. This is working version combination.
|
Yes of course :D
That worked, thanks! 👍 |
I had everything the same except my constrainlayout was in 2.0.0-beta2. |
Just curious has this been resolved yet? Today I tried to upgrading my androidx.navigation:navigation-fragment-ktx to 2.1.0-rc01 and my viewModel() is not resolving. |
Thank you, my friend ❤️ |
After looking at the issue deeply. I found that my androidx.core:core-ktx:1.0.2 was causing issues with viewModel() not resolving. I upgraded this to androidx.core:core-ktx:1.1.0-rc03 and everything worked. I was able to upgrade my ConstraintLayout to 2.0.0 beta2 and navigation libraries to 2.1.0 rc01. |
In my case it was to update |
I've had the same problem, but I've found a definite solution.
|
yes, it does work. although I would have preferred an automatic import. I have to do this manually in all my fragments/activities. |
implementation "androidx.activity:activity-ktx:1.3.1" just implement this lib and problem solve |
viewModel not resolving
I am using following dependencies
org.koin:koin-android:1.0.2
org.koin:koin-androidx-scope:1.0.2
org.koin:koin-androidx-viewmodel:1.0.2
The text was updated successfully, but these errors were encountered: