撰写应用程序在 dispatchTouchEvent 上崩溃

Compose app crashes on dispatchTouchEvent

我的 Play 商店仪表板中重复列出了一个崩溃事件。所有实例均来自 Samsung Galaxy S 系列设备。

我无法在我的任何设备或模拟器上重现此崩溃,并且堆栈跟踪不包含我的代码的任何部分。

我唯一可以从这个跟踪中推断出的是,这是在某个触摸事件上发生的,但这几乎不是一个线索。

我将完整的堆栈跟踪放在这里,希望有人能提出一个想法。

java.lang.IllegalArgumentException: 
      at androidx.compose.ui.node.MeasureAndLayoutDelegate.doRemeasure (MeasureAndLayoutDelegate.kt:177)
      at androidx.compose.ui.node.MeasureAndLayoutDelegate.remeasureAndRelayoutIfNeeded (MeasureAndLayoutDelegate.kt:228)
      at androidx.compose.ui.node.MeasureAndLayoutDelegate.access$remeasureAndRelayoutIfNeeded (MeasureAndLayoutDelegate.kt:38)
      at androidx.compose.ui.node.MeasureAndLayoutDelegate.measureAndLayout (MeasureAndLayoutDelegate.kt:201)
      at androidx.compose.ui.platform.AndroidComposeView.measureAndLayout (AndroidComposeView.android.kt:662)
      at androidx.compose.ui.platform.AndroidComposeView.handleMotionEvent-8iAsVTc (AndroidComposeView.android.kt:1073)
      at androidx.compose.ui.platform.AndroidComposeView.dispatchTouchEvent (AndroidComposeView.android.kt:1059)
      at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3923)
      at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:3597)
      at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3923)
      at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:3597)
      at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3923)
      at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:3597)
      at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3923)
      at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:3597)
      at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:1015)
      at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1962)
      at android.app.Dialog.dispatchTouchEvent (Dialog.java:1264)
      at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:973)
      at android.view.View.dispatchPointerEvent (View.java:15335)
      at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:7794)
      at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:7567)
      at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6901)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6958)
      at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6924)
      at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:7122)
      at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:6932)
      at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:7179)
      at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6905)
      at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6958)
      at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6924)
      at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:6932)
      at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6905)
      at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:10354)
      at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:10202)
      at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:10158)
      at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:10486)
      at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:259)
      at android.view.InputEventReceiver.nativeConsumeBatchedInputEvents (Native Method)
      at android.view.InputEventReceiver.consumeBatchedInputEvents (InputEventReceiver.java:239)
      at android.view.ViewRootImpl.doConsumeBatchedInput (ViewRootImpl.java:10434)
      at android.view.ViewRootImpl$ConsumeBatchedInputRunnable.run (ViewRootImpl.java:10575)
      at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1108)
      at android.view.Choreographer.doCallbacks (Choreographer.java:866)
      at android.view.Choreographer.doFrame (Choreographer.java:789)
      at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1092)
      at android.os.Handler.handleCallback (Handler.java:938)
      at android.os.Handler.dispatchMessage (Handler.java:99)
      at android.os.Looper.loopOnce (Looper.java:226)
      at android.os.Looper.loop (Looper.java:313)
      at android.app.ActivityThread.main (ActivityThread.java:8663)
      at java.lang.reflect.Method.invoke (Native Method)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:567)
      at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1135)

所以问题是,我在 AlertDialog 中有一个 LazyColumn,当​​ LazyColumn 在相对较长的列表上滚动时出现异常。显然,这会导致 Compose 无法跟踪其测量值。

而且我太快将它固定在 Galaxy 手机上(对不起三星!)

诀窍是使用 MaterialDialog 而不是标准的 AlertDialog。