koin
koin copied to clipboard
Unresolve reference viewModule() when updating from 3.1.5 to 3.1.6+
Describe the bug
After updating from v3.1.5 to v3.1.6 lazy initialization by viewModel()
shows an error.
The error still shows up in version 3.2.0.
To Reproduce Steps to reproduce the behavior:
- Update Project's Koin library from v3.1.5 to v3.1.6
Expected behavior Delegate initialization to not be recognized as an error.
Koin project used and used version (please complete the following information):
Working Fine
implementation "io.insert-koin:koin-android:3.1.5"
Showing error
implementation "io.insert-koin:koin-android:3.1.6" // Issue Introduced
implementation "io.insert-koin:koin-android:3.2.0" // Still Existing
Additional moduleDefinition Add any other moduleDefinition about the problem here.
module {
viewModel {
SignUpViewModel(Dependencies(get(), get()))
}
}
Did you try import the extension? Seems to be an IDE thing 🤔
yes the extension is imported, this is happening in any project instance and for other people in my team - We did check but it's weird to see that behavior by doing a minor lib update. 3.1.5 -> 3.1.6 or 3.1.5 -> 3.2.0
I'll check again but do you have any other insight about it?
I was able to replicate this behavior after I added Koin as a dependency to a project that was halfway underway. It seems to be fixed by performing an Invalidate caches/Restart. After I did that, I was able to import the viewModel()
extension function. This is on Android Studio Dolphin 2021.3.1
I think the issue may be the change from:
inline fun <reified T : ViewModel> ComponentCallbacks.viewModel(
to
inline fun <reified T : ViewModel> ComponentActivity.viewModel(
This appears to cause the issue with activities that are based on AppCompatActivity
?
Which used to not have an issue in 3.15
it looks like by Inject() may work for these activities though since it uses ComponentCallbacks not the ComponentActivity?
There appears to be some sort of ambiguity of the ViewModel extensions for ComponentActivity
and Fragment
for AppCompatActivity
that didn't seem to exist in 3.15 when the activity used the ComponentCallbacks
extension?
It's weird because it compiles fine, it just can't seem to auto import the right extension and if you manually import org.koin.androidx.viewmodel.ext.android
and click on the by viewModel()
it can't figure out which declaration to go to.
Still happens in 3.2.2 - Invalidate caches/Restart doesn't seem to affect it.
@arnaudgiuliani
This may be related to this bug in AndroidStudio/IntelliJ: https://issuetracker.google.com/u/1/issues/178403178#comment17 somehow AndroidStudio gets confused about the Fragment unless you do the resolution strategy outlined in the comment which seems to fix the errors (the IDE can now resolve the methods). The changes in 3.2.0 seem to have exposed this problem with the wayby viewmodel()
was changed.
Great, thanks for the investigation @jt-gilkeson 👍
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.