android - 迁移到androidx后没有 super 方法getLifecycle()

标签 android android-lifecycle androidx

我一直在尝试迁移我的应用程序以使用 androidx,但我似乎遇到了一个奇怪的错误。从我调用 getLifeCycle() 时扩展 AppCompatActivity 的 Activity 中,它会引发以下异常

 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)

我相信 AppCompatActivity 应该实现 LifecycleOwner 但事实并非如此。难道我做错了什么? 这是我的 gradle 依赖项

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"

最佳答案

您应该将 androidx.appcompat:appcompat 版本更改为 1.1.0-alpha04

关于android - 迁移到androidx后没有 super 方法getLifecycle(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53229259/

相关文章:

android - 如何检索在 XML 中定义的 fragment 实例?

android - 错误 : ConnectionResult{statusCode=INTERNAL_ERROR, 分辨率 = null}

安卓NDK。 #define LOGI(...) 是什么意思。以及一些基本问题

android - 当电话打断应用程序时,android 应用程序会发生什么情况?

Android 资源链接失败 activity_main.xml :19: error: attribute android:defaultNavHost not found after adding navigation components

android - 如何为原生移动应用程序进行部分产品发布?

android - 恢复 fragment 的正确方法是什么?

java - Android 后退按钮永久删除 Activity

java - 启用后新的 PreferenceScreen 无法打开

java - Android TextInputEditText/TextInputLayout 截断错误信息