在 Android 模拟器中更改屏幕尺寸(Tavle、可折叠、手机)时,我遇到了这个问题:
java.lang.ClassCastException: androidx.compose.foundation.layout.ConsumedInsetsModifier cannot be cast to androidx.compose.ui.input.pointer.PointerInputModifier
at androidx.compose.ui.node.BackwardsCompatNode.onCancelPointerInput(BackwardsCompatNode.kt:354)
at androidx.compose.ui.node.PointerInputModifierNode.onDensityChange(PointerInputModifierNode.kt:102)
at androidx.compose.ui.node.LayoutNode.setDensity(LayoutNode.kt:669)
at androidx.compose.ui.node.LayoutNode.setCompositionLocalMap(LayoutNode.kt:696)
at androidx.compose.ui.node.ComposeUiNode$Companion$SetResolvedCompositionLocals$1.invoke(ComposeUiNode.kt:44)
at androidx.compose.ui.node.ComposeUiNode$Companion$SetResolvedCompositionLocals$1.invoke(ComposeUiNode.kt:43)
at androidx.compose.runtime.Applier.apply(Applier.kt:180)
at androidx.compose.runtime.changelist.Operation$UpdateNode.execute(Operation.kt:554)
at androidx.compose.runtime.changelist.Operations.executeAndFlushAllPendingOperations(Operations.kt:332)
at androidx.compose.runtime.changelist.ChangeList.executeAndFlushAllPendingChanges(ChangeList.kt:88)
at androidx.compose.runtime.CompositionImpl.applyChangesInLocked(Composition.kt:1033)
at androidx.compose.runtime.CompositionImpl.applyChanges(Composition.kt:1064)
at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:669)
at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke(Recomposer.kt:576)
at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame(AndroidUiFrameClock.android.kt:39)
at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch(AndroidUiDispatcher.android.kt:108)
at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch(AndroidUiDispatcher.android.kt:41)
at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame(AndroidUiDispatcher.android.kt:69)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1404)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1415)
at android.view.Choreographer.doCallbacks(Choreographer.java:1015)
at android.view.Choreographer.doFrame(Choreographer.java:941)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1389)
at android.os.Handler.handleCallback(Handler.java:959)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loopOnce(Looper.java:232)
at android.os.Looper.loop(Looper.java:317)
at android.app.ActivityThread.main(ActivityThread.java:8674)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [androidx.compose.runtime.PausableMonotonicFrameClock@8f5b374, androidx.compose.ui.platform.MotionDurationScaleImpl@d02f09d, StandaloneCoroutine{Cancelling}@5fe7912, AndroidUiDispatcher@c2938e3]
我使用可调整大小的 API VanillaIceCreame 在不同的屏幕尺寸上输入文本。
根据错误,我的代码没有问题,否则我会在代码中看到对代码行的引用。
Hier是Android Studio的相关信息:
Android Studio Ladybug | 2024.2.1 Patch 2
Build #AI-242.23339.11.2421.12550806, built on October 24, 2024
Runtime version: 21.0.3+-79915917-b509.11 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.1
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 4096M
Cores: 8
Metal Rendering is ON
Registry:
ide.instant.shutdown=false
debugger.new.tool.window.layout=true
ide.experimental.ui=true
i18n.locale=
terminal.new.ui=true
Non-Bundled Plugins:
com.intellij.marketplace (242.22855.133)
dev.j-a.swift (1.1.0.354-242)
tarn.gradle.dependencies (2.0.0)
com.jetbrains.kmm (0.8.3(242)-5)
具体问题是什么?
在以前版本的 Android Studio 中我没有任何类似的问题。
我刚刚使用与您相同的设置进行了测试:
在屏幕尺寸之间切换时,我无法使用简单的演示 Compose 应用程序重现任何崩溃。请确保您安装了最新的模拟器版本。首先,在Android Studio中打开
SDK Manager
:
然后,切换到
SDK Tools
选项卡并找到与模拟器相关的库:
如果有任何可用更新,请安装它们。然后,删除旧的可调整大小模拟器并重新创建它。
如果问题仍然存在,请尝试创建一个空的新 Compose 项目并运行它。如果您也遇到了该问题,请在 Google Issue Tracker 上提出问题。可调整大小的模拟器仍处于实验状态。