在 FlutterSplashView.java 为我发布的应用程序之一获取 ClasscastException

Getting ClasscastException at FlutterSplashView.java for one of my published APP

我的 APP 在 Google Play 商店发布,但在某些设备上崩溃了。它与启动画面有关吗?我没有实现任何启动画面,所以不确定是什么原因导致此错误。

java.lang.ClassCastException: at io.flutter.embedding.android.FlutterSplashView.onRestoreInstanceState (FlutterSplashView.java) at android.view.View.dispatchRestoreInstanceState (View.java:20262) at android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:4039) at android.view.ViewGroup.dispatchRestoreInstanceState (ViewGroup.java:4045) at android.view.View.restoreHierarchyState (View.java:20240) at com.android.internal.policy.PhoneWindow.restoreHierarchyState (PhoneWindow.java:2184) at android.app.Activity.onRestoreInstanceState (Activity.java:1195) at android.app.Activity.performRestoreInstanceState (Activity.java:1150) at android.app.Instrumentation.callActivityOnRestoreInstanceState (Instrumentation.java:1321) at android.app.ActivityThread.handleStartActivity (ActivityThread.java:3161) at android.app.servertransaction.TransactionExecutor.performLifecycleSequence (TransactionExecutor.java:180) at android.app.servertransaction.TransactionExecutor.cycleToPath (TransactionExecutor.java:165) at android.app.servertransaction.TransactionExecutor.executeLifecycleState (TransactionExecutor.java:142) at android.app.servertransaction.TransactionExecutor.execute (TransactionExecutor.java:70) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1955) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:214) at android.app.ActivityThread.main (ActivityThread.java:7091) at java.lang.reflect.Method.invoke (Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:494) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:965)

根据 Flutter's repo 上的这个问题,如果您使用的是 Flutter 1.12.13+hotfix.9 或更早版本, 推荐的方法是设置一个不会混淆 FlutterSplashView.SavedState class.

的 Proguard 规则

<your-app-directory>/android/app/proguard-rules.pro中添加这一行:

-keep public class io.flutter.embedding.android.FlutterSplashView.$SavedState { *; }

另请查看这篇关于 Flutter and Android Obfuscation 的文章。