Reputation: 392
On which situation android-build/android-studio shows these errors?
Cannot access androidx.lifecycle.LifecycleOwner and
Cannot access androidx.lifecycle.ViewModelStoreOwner
What is the meaning of this errors? I found that adding androidx.lifecycle:lifecycle-viewmodel
as dependency solves these errors, I want to know the meaning of the error in terms of Android Activity LifeCycle(Or is it related to lifecycle or not).
For example in this code call to `super' onSavedInstanceState shows this error
public class AppActivity extends FragmentActivity {
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState); // Cannot access androidx.lifecycle.LifecycleOwner
}
}
When should I use Android Lifecycles,and when should I avoid using it?
Upvotes: 12
Views: 8491
Reputation: 33
File > Invalidate Caches / Restart
- Worked Actually.
Also I updated the gradle implementations with its latest version release.
Upvotes: 1
Reputation: 151
Update to the latest appcompat library version can help with this.
androidx.appcompat:appcompat:1.3.0-alpha01
Upvotes: 6
Reputation: 11640
For the sake of completeness, even after adding the dependencies and having properly migrated to androidx using the one-click refactoring, you would still get intellisense errors against your Kotlin code saying
Cannot access 'Cannot access androidx.lifecycle.LifecycleOwner' ...
, although the project builds fine.
Then you would have to
project/.idea
folder~/.gradle
folderFile > Invalidate Caches / Restart
won't work.
Upvotes: 1
Reputation: 151
add this to your gradle dependencies
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
Upvotes: 15