应用程序在少数模拟器上运行,但在真实设备上崩溃 [重复]

Posted

技术标签:

【中文标题】应用程序在少数模拟器上运行,但在真实设备上崩溃 [重复]【英文标题】:App runs on few emulators but crashes on real device [duplicate] 【发布时间】:2022-01-22 05:59:08 【问题描述】:

我正在开发一个计算器应用程序。该应用程序在少数模拟器上运行,但不能在真实设备上运行。 logcat中有很多错误。我很困惑如何解决这些错误。

2021-12-20 21:02:39.726 9164-9164/? E/hmad.calculato: Unknown bits set in runtime_flags: 0x8000
2021-12-20 21:02:40.530 9164-9164/com.ahmad.calculator E/androidRuntime: FATAL EXCEPTION: main
    Process: com.ahmad.calculator, PID: 9164
    java.lang.IllegalArgumentException: Linear gradient requires 'angle' attribute to be a multiple of 45
        at android.graphics.drawable.GradientDrawable$GradientState.updateGradientStateOrientation(GradientDrawable.java:2255)
        at android.graphics.drawable.GradientDrawable$GradientState.getOrientation(GradientDrawable.java:2243)
        at android.graphics.drawable.GradientDrawable.ensureValidRect(GradientDrawable.java:1307)
        at android.graphics.drawable.GradientDrawable.draw(GradientDrawable.java:725)
        at android.view.View.getDrawableRenderNode(View.java:22113)
        at android.view.View.drawBackground(View.java:22047)
        at android.view.View.draw(View.java:21800)
        at android.widget.Switch.draw(Switch.java:1299)
        at android.view.View.updateDisplayListIfDirty(View.java:20642)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.updateDisplayListIfDirty(View.java:20633)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.updateDisplayListIfDirty(View.java:20633)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1994)
        at android.view.View.draw(View.java:21820)
        at android.view.View.updateDisplayListIfDirty(View.java:20642)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.updateDisplayListIfDirty(View.java:20633)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.updateDisplayListIfDirty(View.java:20633)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.updateDisplayListIfDirty(View.java:20633)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.updateDisplayListIfDirty(View.java:20633)
        at android.view.View.draw(View.java:21525)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4542)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4279)
        at android.view.View.draw(View.java:21820)
        at com.android.internal.policy.DecorView.draw(DecorView.java:869)
        at android.view.View.updateDisplayListIfDirty(View.java:20642)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:575)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:581)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:654)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:4126)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3914)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3220)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2051)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8456)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1065)
        at android.view.Choreographer.doCallbacks(Choreographer.java:889)
        at android.view.Choreographer.doFrame(Choreographer.java:816)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1050)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7830)
2021-12-20 21:02:40.530 9164-9164/com.ahmad.calculator E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1040)

【问题讨论】:

【参考方案1】:

根据 Android 文档:

https://developer.android.com/reference/android/graphics/drawable/GradientDrawable

android:angle

渐变的角度,仅用于线性渐变。必须是一个 [0, 315] 范围内 45 的倍数。

可能是浮点值,例如“1.2”。

比较您的模拟器和手机上的 Android 版本可能是值得的。

在任何情况下,不是 45 倍数的线性渐变绝对是一个“错误”,无论应用是否发生实际崩溃。

【讨论】:

以上是关于应用程序在少数模拟器上运行,但在真实设备上崩溃 [重复]的主要内容,如果未能解决你的问题,请参考以下文章

在flutter中从image_picker包中打开相机会导致真实设备上的应用程序崩溃,但在模拟器(android)中运行良好

Xamarin表单,在Visual Studio Android Emulator上运行的应用程序但在真实设备上崩溃

当我在真实设备中打开活动时应用程序崩溃

应用程序在 iPad 设备上崩溃但在模拟器上运行

AVPlayer 导致模拟器崩溃但在设备上运行良好

我的应用程序正在模拟器上运行并完全运行,但在物理设备上崩溃