Cannot access androidx.lifecycle.LifecycleOwner, what is the meaning of error in Android?
Asked Answered
H

4

11

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?

Halide answered 2/9, 2019 at 20:1 Comment(0)
F
14

add this to your gradle dependencies

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
Fatal answered 29/1, 2020 at 14:50 Comment(1)
i try this but not workingWheelhorse
B
5

Update to the latest appcompat library version can help with this.

androidx.appcompat:appcompat:1.3.0-alpha01
Baal answered 28/7, 2020 at 9:4 Comment(0)
D
1

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

  1. Quit Android Studio
  2. Remove project/.idea folder
  3. Remove ~/.gradle folder
  4. Restart Android Studio

File > Invalidate Caches / Restart won't work.

Dextrogyrate answered 29/5, 2020 at 2:9 Comment(2)
Deleting the files solved the issue for me. Thanks!Interrupted
i try this by not workingWheelhorse
T
1

File > Invalidate Caches / Restart - Worked Actually.

Also I updated the gradle implementations with its latest version release.

Tiaratibbetts answered 9/8, 2022 at 16:8 Comment(1)
this solution is not workingWheelhorse

© 2022 - 2024 — McMap. All rights reserved.