恢复GoogleMaps对象状态时的ClassNotFoundException

时间:2016-11-11 23:11:29

标签: android google-maps classloader classnotfoundexception android-savedstate

我的应用在从活动返回后尝试恢复GoogleMapmapView)对象的状态时一直崩溃。 mapView位于自定义支持lib v4 FragmentMyFragment)中,其本身嵌入AppCompatActivityMyActivity)。这些组件的设置是正常的。我的设备是开发人员配置的,可以在推送时销毁所有Activity

推送并弹出另一个Activity后,我的Fragment onCreateView(LayoutInflater, ViewGroup, Bundle state)方法被调用,然后崩溃

  mapView.onCreate(state);

在底部产生痕迹。

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

事实上,我能做的唯一事情就是启用Instant Run并直接从Android Studio运行。在这种情况下,一切都很好。如果禁用“即时运行”并且我从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$3.zzb(Unknown Source)
11-11 13:37:42.165 18389 18389 E Parcel  :  at com.google.android.gms.dynamic.zza$1.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.access$1100(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.access$1100(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$3.zzb(Unknown Source)
11-11 13:37:42.170 18389 18389 E AndroidRuntime:    at com.google.android.gms.dynamic.zza$1.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

1 个答案:

答案 0 :(得分:1)

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