java.lang.NoSuchMethodError: No super method

java.lang.NoSuchMethodError: No super method

尝试在 Android.I 中使用 CameraX 我正在使用 code link 。但是我遇到了错误
java.lang.NoSuchMethodError: 没有超级方法 getLifecycle()Landroidx/lifecycle/Lifecycle;在 class Landroidx/core/app/ComponentActivity;或其超级 classes

问题出在 appcompact 依赖项中。如果您检查您正在使用的版本的源代码 1.0.2ComponentActivity class 中没有超级方法,而 FragmentActivity 正在尝试调用该方法。

修复,您需要升级版本到1.1.0-rc01。在此版本中 FragmentActivity 使用 LifecycleRegistry 获取 LifeCycle

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'

请更新Android AppCompat 库 V7 查看最新版本 1.1.0-rc01 但您使用的是 1.0.2 请将此行替换为 build.gradle

implementation 'androidx.appcompat:appcompat:1.0.2'

implementation 'androidx.appcompat:appcompat:1.1.0-rc01'

您将从下方找到更新的依赖项 link。 https://mvnrepository.com/artifact/androidx.appcompat/appcompat?repo=google

Add in build.gradle of app module

android { 

   compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}