Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access android.arch.lifecycle.LifecycleOwner on fragment?

This happens when i extend from an abstract base fragment like so:

public abstract class BaseFragment<T extends BasePresenter, E extends BaseModel> extends Fragment {
....
}

, but the app still build without any errors. below is my build.gradle config:

android {
    compileSdkVersion 27
    buildToolsVersion '26.0.2'
    defaultConfig
    {
        multiDexEnabled true
        minSdkVersion 21
        targetSdkVersion 27
    } 
}
like image 296
Irshu Avatar asked Dec 21 '17 11:12

Irshu


3 Answers

Add following line to gradle

implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
like image 103
Mohammad Bilal Avatar answered Oct 16 '22 14:10

Mohammad Bilal


Solution 1:

LifecycleOwner : A class that has an Android lifecycle. These events can be used by custom components to handle lifecycle changes without implementing any code inside the Activity or the Fragment.

To access LifecycleOwner class add following dependency in your app build.gradle file.

implementation "android.arch.lifecycle:extensions:1.1.1"

Solution 2:

Add following support compat dependency in your app build.gradle file.

implementation 'com.android.support:support-compat:27.1.1'
like image 30
Vicky Avatar answered Oct 16 '22 14:10

Vicky


I had this same issue , adding this to the apps build.gradle might fix the issue

annotationProcessor "android.arch.lifecycle:common-java8:1.1.1"
like image 2
user1273299 Avatar answered Oct 16 '22 13:10

user1273299