"Cannot access android.arch.lifecycle.ViewModelStoreOwner" in android studio 3.2
Asked Answered
L

2

5

I have recently upgraded my android studio to version 3.2, and since everywhere I try to access fragment/activity attributes from my ViewModel classes, I get this "Cannot access android.arch.lifecycle.ViewModelStoreOwner" message:

example of the error message

It does not affect compilation, but this annoying message pops in a lot of class.

Any ideas?

PS: I have already tried "Invalidate caches and restart" several times

Leavening answered 1/10, 2018 at 13:14 Comment(0)
R
6

Just got the same problem after update, this helped: Add this line to your module’s build.gradle script:

dependencies {
    ...
    implementation 'android.arch.lifecycle:extensions:1.1.1'
}

Found it here: Adding Components to your Project

Roderich answered 7/10, 2018 at 20:24 Comment(4)
Maybe you should check the description for AndroidX, the link above. Also I found that the “implementation” for lifecycle.extensions is not required anymore after I have changed the ExoPlayer library reference to 2.8.4Roderich
Show your build.gradle script content.Roderich
It works for me but Can anyone explain why we need this dependencies.?I am not using android architectural component in my project. I have updated targetSdkversion 28.Kilpatrick
I would also need an explanation for the question. I am also not using any architectural components in the project. Then, why do we need to add this dependency to avoid this error?Caravette
W
1

I have faced the same issue and I resolved this issue by updating android support libraries in build.gradle file.

I would recommend updating your android support libraries to 27.1.1 or newer. No need to add this :

implementation 'android.arch.lifecycle:extensions:1.1.1'
Wakashan answered 4/1, 2019 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.