Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

android - ViewTreeLifecycleOwner not found from DecorView@2da7146[MyActivity]

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.

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")
                }
            }
        }
    }

UPDATE

Apparently you need to use androidx.appcompat:appcompat:1.3.0-beta01

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try updating the dependency of AppCompat to rc01 version. This solved the problem for me.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...