本文介绍了未从 DecorView@2da7146[MyActivity] 中找到 ViewTreeLifecycleOwner的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从 compose alpha-11
更新到 alpha-12
(或 beta-01
)后,每当我打开一个具有撰写视图的活动或片段.
After updating from compose alpha-11
to alpha-12
(or beta-01
) I am getting this crash whenever I open an activity or fragment that has compose views.
我正在使用实现 LifecycleOwner
的 AppCompatActivity
,所以这非常奇怪.
I am using AppCompatActivity
which implements LifecycleOwner
, so this is extremely odd.
java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from DecorView@2da7146[MyActivity]
at androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:214)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.access$createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:1)
at androidx.compose.ui.platform.WindowRecomposerFactory$Companion$LifecycleAware$1.createRecomposer(WindowRecomposer.android.kt:98)
at androidx.compose.ui.platform.WindowRecomposerPolicy.createAndInstallWindowRecomposer$ui_release(WindowRecomposer.android.kt:151)
at androidx.compose.ui.platform.WindowRecomposer_androidKt.getWindowRecomposer(WindowRecomposer.android.kt:199)
at androidx.compose.ui.platform.AbstractComposeView.ensureCompositionCreated(ComposeView.android.kt:176)
at androidx.compose.ui.platform.AbstractComposeView.onAttachedToWindow(ComposeView.android.kt:207)
at android.view.View.dispatchAttachedToWindow(View.java:20014)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3589)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3596)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2223)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1888)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8511)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
at android.view.Choreographer.doCallbacks(Choreographer.java:761)
at android.view.Choreographer.doFrame(Choreographer.java:696)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7050)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
我的代码看起来很简单:
My code looks really simple:
class MyActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
Text(text = "compose")
}
}
}
}
更新
显然你需要使用 androidx.appcompat:appcompat:1.3.0-beta01
推荐答案
尝试将 AppCompat
的依赖更新到 rc01
版本.这为我解决了问题.
Try updating the dependency of AppCompat
to rc01
version.This solved the problem for me.
实现'androidx.appcompat:appcompat:1.3.0-rc01'
这篇关于未从 DecorView@2da7146[MyActivity] 中找到 ViewTreeLifecycleOwner的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!