Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 668
Clapa Lucian Avatar asked Feb 26 '21 08:02

Clapa Lucian


People also ask

What version of Android has the support for viewtreelifecycleowner?

The support for ViewTreeLifecycleOwner was introduced in the AppCompat with the version 1.3.0. Use: implementation 'androidx.appcompat:appcompat:1.3.0-rc01' Does this answer your question? ViewTreeLifecycleOwner not found from DecorView@2da7146 [MyActivity]

How do I get the lifecycleowner of a view?

Set the LifecycleOwner responsible for managing the given View . Calls to get (View) from this view or descendants will return lifecycleOwner . This should only be called by constructs such as activities or fragments that manage a view tree and reflect their own lifecycle through a LifecycleOwner.

What happens when a view tree is removed from a window?

The associated lifecycle should report that it is destroyed if the view tree is removed and is not guaranteed to later become reattached to a window. Content and code samples on this page are subject to the licenses described in the Content License.


2 Answers

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

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

like image 77
Marc Widmer Montragull Avatar answered Sep 24 '22 12:09

Marc Widmer Montragull


I've encountered same issue with BottomSheetDialogFragment You have to upgrade fragment to 1.3.1

Thanks to @clapa-lucian, you can find more about in this issue

like image 45
amrro Avatar answered Sep 23 '22 12:09

amrro