Skip to content
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

Android Studio complains that by viewModel is an unresolved reference #1498

Closed
Nattle opened this issue Jan 4, 2023 · 8 comments
Closed
Labels

Comments

@Nattle
Copy link

Nattle commented Jan 4, 2023

Android studio reports an error in the code when using by viewModel() in an AppCompatActivity

To Reproduce
See attached snip of our app.
Simply creating an activity which extends AppCompatActivity reports a compilation error.
Note that the project compiles just fine.

This occurs on several versions of Android Studio, currently using a mix of Chipmonk, Dolphin, and Eel.

Expected behavior
Android studio doesn't report and error.

Koin project used and used version (please complete the following information):

implementation "io.insert-koin:koin-core:$koin_version"

Screen Shot 2022-12-12 at 12 45 59 PM

Screen Shot 2023-01-04 at 10 25 50 AM

@arnaudgiuliani arnaudgiuliani added the question Usage question label Jan 9, 2023
@arnaudgiuliani
Copy link
Member

can you extract your ViewModel class declaration outside, to check?

@Nattle
Copy link
Author

Nattle commented Jan 9, 2023

Do you mean to a separate file? The bulk of our view models are defined in different files or rarely other gradle modules. You can see in the first file that the view model is declared in another file.

It doesn't complain that the view model is the wrong type, since in Fragments I can use the same VM class. It's only activities which show this error.

@arnaudgiuliani
Copy link
Member

really weird 🤔

Is it a project config issue? Can you try checkout this tutorial: https://insert-koin.io/docs/quickstart/android-viewmodel

@ForceTower
Copy link

I have the same issue, but I'm using the vanilla by viewModels from androidx.

I think this is an android studio bug. If I move my implementation dependencies a bit the issue disappears...

@plugowskidroids
Copy link

Same problem here, code works fine but AS reports error 😞 @ForceTower what do you mean by moving implementation dependencies?

@ForceTower
Copy link

Sometimes l just need to go to my grade file and move the dependencies around and that fixes the issue...

@stale
Copy link

stale bot commented Aug 21, 2023

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.

@stale stale bot added the status:wontfix label Aug 21, 2023
@Nattle
Copy link
Author

Nattle commented Aug 21, 2023

Seems to have resolved with current versions of android studio.

@Nattle Nattle closed this as completed Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants