恢复 GoogleMaps 对象状态时出现 ClassNotFoundException

ClassNotFoundException upon restoring GoogleMaps object state

在从 Activity 返回后尝试恢复我的 GoogleMap (mapView) 对象的状态时,我的应用程序一直崩溃。 mapView 位于自定义支持库 v4 Fragment (MyFragment) 中,它本身嵌入在 AppCompatActivity (MyActivity) 中。这些组件的设置是正常的。我的设备由开发人员配置为在推送时销毁所有 Activity

在推入和弹出另一个 Activity 时,我的 FragmentonCreateView(LayoutInflater, ViewGroup, Bundle state) 方法被调用,并在

上崩溃
  mapView.onCreate(state);

在底部生成轨迹。

statenull 时,首次创建时 不会 发生崩溃。启用或禁用 MultiDex 或 Proguard 的任何组合(我能找到)都无法解决崩溃问题。

事实上,我唯一能做的就是直接从 Android Studio 启用 Instant 运行 和 运行ning。在这种情况下,一切都很好。如果 Instant 运行 被禁用并且我 运行 来自 Android Studio,则会出现崩溃。


更新:

上周,Google 发布了 Android Build Tools v5.0.1 和 Google Play Services v10.0。更新后,这个问题似乎已经解决了。但是,我将保留这个问题以供记录,以查看是否有其他想法出现。下面 Aлекс 的想法很好,我可以尝试一下。


11-11 13:37:42.165 18389 18389 E Parcel  : Class not found when unmarshalling: android.support.v7.widget.LinearLayoutManager$SavedState
11-11 13:37:42.165 18389 18389 E Parcel  : java.lang.ClassNotFoundException: android.support.v7.widget.LinearLayoutManager$SavedState
11-11 13:37:42.165 18389 18389 E Parcel  :  at java.lang.Class.classForName(Native Method)
11-11 13:37:42.165 18389 18389 E Parcel  :  at java.lang.Class.forName(Class.java:324)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Parcel.readParcelableCreator(Parcel.java:2404)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Parcel.readParcelable(Parcel.java:2358)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Parcel.readValue(Parcel.java:2264)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.BaseBundle.unparcel(BaseBundle.java:221)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Bundle.getBundle(Bundle.java:763)
11-11 13:37:42.165 18389 18389 E Parcel  :  at aby.a(:com.google.android.gms.DynamiteModulesB:74)
11-11 13:37:42.165 18389 18389 E Parcel  :  at maps.ad.t.a(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at maps.ad.R.a(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at xx.onTransact(:com.google.android.gms.DynamiteModulesB:66)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Binder.transact(Binder.java:387)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.onCreate(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.maps.MapView$zza.onCreate(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.dynamic.zza.zzb(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.dynamic.zza.zza(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.maps.MapView$zzb.zzbsp(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.maps.MapView$zzb.zza(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.dynamic.zza.zza(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.dynamic.zza.onCreate(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.maps.MapView.onCreate(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.myco.myapp.MyFragment.onCreateView(MyFragment.java:235)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1277)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2154)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:603)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:181)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.myco.myapp.main.MainActivity.onStart(MainActivity.java:176)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.Activity.performStart(Activity.java:6916)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3218)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.ActivityThread.access00(ActivityThread.java:222)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.os.Looper.loop(Looper.java:158)
11-11 13:37:42.165 18389 18389 E Parcel  :  at android.app.ActivityThread.main(ActivityThread.java:7230)
11-11 13:37:42.165 18389 18389 E Parcel  :  at java.lang.reflect.Method.invoke(Native Method)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
11-11 13:37:42.165 18389 18389 E Parcel  : Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.LinearLayoutManager$SavedState" on path: DexPathList[[zip file "/data/data/com.google.android.gms/app_chimera/m/00000018/DynamiteModulesB_GmsCore_prodmnc_hdpi_release.apk"],nativeLibraryDirectories=[/data/user/0/com.google.android.gms/app_chimera/m/00000018/n/armeabi-v7a, /data/user/0/com.google.android.gms/app_chimera/m/00000018/n/armeabi, /vendor/lib, /system/lib]]
11-11 13:37:42.165 18389 18389 E Parcel  :  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
11-11 13:37:42.165 18389 18389 E Parcel  :  at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.chimera.container.internal.DelegateLastPathClassLoader.loadClass(:com.google.android.gms:34)
11-11 13:37:42.165 18389 18389 E Parcel  :  at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
11-11 13:37:42.165 18389 18389 E Parcel  :  ... 44 more
11-11 13:37:42.165 18389 18389 E Parcel  :  Suppressed: java.lang.ClassNotFoundException: android.support.v7.widget.LinearLayoutManager$SavedState
11-11 13:37:42.165 18389 18389 E Parcel  :      at java.lang.Class.classForName(Native Method)
11-11 13:37:42.165 18389 18389 E Parcel  :      at java.lang.BootClass
11-11 13:37:42.170 18389 18389 D AndroidRuntime: Shutting down VM
11-11 13:37:42.170 18389 18389 E AndroidRuntime: FATAL EXCEPTION: main
11-11 13:37:42.170 18389 18389 E AndroidRuntime: Process: com.myco.myapp, PID: 18389
11-11 13:37:42.170 18389 18389 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myco.myapp/com.myco.myapp.main.MainActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v7.widget.LinearLayoutManager$SavedState
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3255)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3351)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.ActivityThread.access00(ActivityThread.java:222)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1796)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Handler.dispatchMessage(Handler.java:102)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Looper.loop(Looper.java:158)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.ActivityThread.main(ActivityThread.java:7230)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at java.lang.reflect.Method.invoke(Native Method)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
11-11 13:37:42.170 18389 18389 E AndroidRuntime: Caused by: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: android.support.v7.widget.LinearLayoutManager$SavedState
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Parcel.readParcelableCreator(Parcel.java:2432)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Parcel.readParcelable(Parcel.java:2358)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Parcel.readValue(Parcel.java:2264)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Parcel.readArrayMapInternal(Parcel.java:2614)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.BaseBundle.unparcel(BaseBundle.java:221)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Bundle.getBundle(Bundle.java:763)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at aby.a(:com.google.android.gms.DynamiteModulesB:74)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at maps.ad.t.a(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at maps.ad.R.a(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at xx.onTransact(:com.google.android.gms.DynamiteModulesB:66)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.os.Binder.transact(Binder.java:387)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.maps.internal.IMapViewDelegate$zza$zza.onCreate(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.maps.MapView$zza.onCreate(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.dynamic.zza.zzb(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.dynamic.zza.zza(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.maps.MapView$zzb.zzbsp(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.maps.MapView$zzb.zza(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.dynamic.zza.zza(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.dynamic.zza.onCreate(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.maps.MapView.onCreate(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.myco.myapp.MyFragment.onCreateView(MyFragment.java:235)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.Fragment.performCreateView(Fragment.java:2087)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1113)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1295)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1277)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:2154)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.FragmentController.dispatchActivityCreated(FragmentController.java:201)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:603)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.support.v7.app.AppCompatActivity.onStart(AppCompatActivity.java:181)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.myco.myapp.main.MainActivity.onStart(MainActivity.java:176)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1266)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.Activity.performStart(Activity.java:6916)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3218)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    ... 9 more
11-11 13:37:42.175  2546  3527 W ActivityManager:   Force finishing activity com.myco.myapp/.main.MainActivity

您应该将地图的状态保存在一个单独的包中,然后将此包作为一个字段放入片段的状态包中。 恢复片段状态时,从片段的恢复状态包中提取地图的包并将其发送到地图的恢复状态方法。