Hi All, we are facing below crash on some device F...
# compose
g
Hi All, we are facing below crash on some device Fatal Exception: java.lang.IllegalStateException: Composed into the View which doesn't propagate ViewTreeLifecycleOwner!
We are unable to reproduce this crash. because on our devices app working fine. getting crash details from Crashlytics dashboard and some customer also facing this issues. Crashlytics logs:- Fatal Exception: java.lang.IllegalStateException: Composed into the View which doesn't propagate ViewTreeLifecycleOwner! at androidx.compose.ui.platform.AndroidComposeView.onAttachedToWindow(AndroidComposeView.android.kt:1157) at android.view.View.dispatchAttachedToWindow(View.java:21475) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3540) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3547) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3547) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3547) at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3547) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2957) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2442) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9399) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1388) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1396) at android.view.Choreographer.doCallbacks(Choreographer.java:1033) at android.view.ChoreographerExtImpl.checkScrollOptSceneEnable(ChoreographerExtImpl.java:420) at android.view.Choreographer.doFrame(Choreographer.java:900) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1371) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:240) at android.os.Looper.loop(Looper.java:351) at android.app.ActivityThread.main(ActivityThread.java:8380) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
j
Do you use Android Activity, and if so which one? If not, using AbstractComposeView or such?
If not using the Google provided variants and some super custom thing you need to provide this manually by setup:
Copy code
fun attachToDecorView(decorView: View?) {
        if (decorView == null) return

        ViewTreeLifecycleOwner.set(decorView, this)
        ViewTreeViewModelStoreOwner.set(decorView, this)
        ViewTreeSavedStateRegistryOwner.set(decorView, this)
    }
g
We are using AppCompatActivity.
Also using the Google provided variants
j
And using the latest AppCompat having automatic support for ViewTreeLifecycleOwner I presume? Also you dont override this anywhere with custom ComposeView or AbstractComposeView?
g
this issues was not there on previous app version
yes
j
Any updates done in appcompat version in that app version? I dont rule out bug in Google library, but thinking about potential problems.
g
i upgrade compose bom version
from 2023.04.01 to 2023.05.01
j
Except from compose BOM version, do you have explicit dependecy version for appcompat?
g
yes
this issue is coming on some devices
mainly on samsung
Copy code
androidx.appcompat:appcompat:1.6.1
j
Hmm yeah not sure, have you filed an issue in Googles bug tracker? Maybe exists one already 🙂
g
yes i already fill it on Googles bug tracker
j
Seems like https://androidx.tech/artifacts/activity/activity-compose/1.7.1-source/androidx/activity/compose/ComponentActivity.kt.html setting stuff correctly at least but hard to know this particular BOM version if any transitive dependecies optimize away code with R8 or such.
g
Any update ? Since we are facing the exact same issue, mostly (58%) from samsung phones. We are also unable to reproduce it on our end
g
try below solution
Copy code
dialogLayout.setViewTreeLifecycleOwner(composeView.findViewTreeLifecycleOwner())
dialogLayout.setViewTreeViewModelStoreOwner(composeView.findViewTreeViewModelStoreOwner())
dialogLayout.setViewTreeSavedStateRegistryOwner(composeView.findViewTreeSavedStateRegistryOwner())
g
Thanks
113 Views