android – No super method getLifecycle() after migrating to androidx-ThrowExceptions

Exception or error:

I have been trying to migrate my app to use androidx but I seem to encounter a strange error. From my activity which extends AppCompatActivity when I call getLifeCycle() it throws the following exception

 Caused by: java.lang.NoSuchMethodError: No super method getLifecycle()Landroidx/lifecycle/Lifecycle; in class Landroidx/core/app/ComponentActivity; or its super classes 
    at androidx.fragment.app.FragmentActivity.getLifecycle(FragmentActivity.java:324)

I believe that AppCompatActivity should be implementing LifecycleOwner but its not. Am I doing something wrong?
Here’s my gradle dependencies

implementation files("libs/jsoup-1.8.3.jar")
implementation "com.github.philjay:MPAndroidChart:v3.0.2"
implementation 'androidx.gridlayout:gridlayout:1.0.0'
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material:1.1.0-alpha01'
implementation "androidx.constraintlayout:constraintlayout:2.0.0-alpha2"
implementation 'androidx.constraintlayout:constraintlayout-solver:2.0.0-alpha2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "com.google.firebase:firebase-messaging:17.3.4"
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.0.1'
implementation "androidx.lifecycle:lifecycle-runtime:2.0.0"

annotationProcessor "androidx.lifecycle:lifecycle-compiler:2.0.0" // use kapt for Kotlin

implementation "de.hdodenhof:circleimageview:2.2.0"
implementation 'androidx.core:core:1.1.0-alpha01'
implementation "com.thoughtbot:expandablerecyclerview:1.0"
implementation "androidx.lifecycle:lifecycle-livedata:2.0.0"
implementation "androidx.lifecycle:lifecycle-viewmodel:2.0.0"
implementation "com.github.franmontiel:FullScreenDialog:1.0.1"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "com.github.apl-devs:appintro:v4.2.3"
implementation "com.google.firebase:firebase-crash:16.2.1"
implementation "com.google.firebase:firebase-core:16.0.5"
How to solve:

You should change the androidx.appcompat:appcompat version to 1.1.0-alpha04

###

Just tried it in verision 1.1.0-alpha01 of androidx.appcompat:appcompat and it is now working.

The LifecycleOwner interface is now implemented by ComponentActivity which is extended by FragmentActivity -> AppCompatActivity. You should now be able to get the lifecycle object from your activities.

###

Reverting back to version 1.0.1 works for me.

implementation "androidx.core:core:1.0.1"

###

In my case my problem was with the version 1.0.0-alpha05 of androidx activity, I revert to 1.0.0-alpha03 and it works fine

Leave a Reply

Your email address will not be published. Required fields are marked *