java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver....

问题

按照官网步骤集成Compose,使用Android Studio创建Compose项目编译成功,但是在真机运行会闪退。

1.下载 Android Studio Arctic Fox
2.按照步骤创建新Compose项目
创建新Compose项目
3.然而运行会报错,报错如下
2021-08-03 10:56:10.728 2496-2496/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.hongjiefly.jetpackcompose, PID: 2496
    java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver.onCreate(androidx.lifecycle.LifecycleOwner)"
        at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(FullLifecycleObserverAdapter.java:36)
        at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
        at androidx.lifecycle.LifecycleRegistry.addObserver(LifecycleRegistry.java:196)
        at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:808)
        at android.view.View.dispatchAttachedToWindow(View.java:20626)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3514)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3521)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2672)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2152)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8675)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1352)
        at android.view.Choreographer.doCallbacks(Choreographer.java:1149)
        at android.view.Choreographer.doFrame(Choreographer.java:1049)
        at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1275)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8010)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

解决方案

原代码 minSdk 21


minSdk21

minSdk 21 改成 minSdk 24

minSdk24

即可正常运行,看来文档写的不靠谱。我的真机是Android10的。

你可能感兴趣的:(java.lang.AbstractMethodError: abstract method "void androidx.lifecycle.DefaultLifecycleObserver....)