title: What causes DeadSystemException with android.gms.dynamite_mapsdynamite?
body: <p>A high number of crashes are reported in connection with a Google map (in lite mode) that is displayed in a recycler view holder.</p>
  
  <ul>
  <li>Only HockeyApp reports these crashes, Firebase Crashlytics does not.</li>
  <li>The crashes are reported hundreds of times for a relatively smaller amount of users, so it seems to affect a certain type of users.</li>
  <li>Occurs on a range of Android version (7.0, 8.0, 8.1, 9), across a variety of devices (Huawei, LG, Samsung, etc).</li>
  <li>The <code>DeadSystemException</code> is always reported in connection with maps, so I would exclude that the device is shutting down for some other reason.</li>
  <li>Tested on Emulator without Google Play Services installed without crash; the map view then displays the expected error message <code>MyApp won't run without Google Play services, which are not supported by your device.</code></li>
  </ul>
  
  <p>The stack trace looks slightly different depending on the device.</p>
  
  <p>For Huawei:</p>
  
  <pre><code>java.lang.RuntimeException: android.os.DeadSystemException
      at huawei.android.app.HwApiCacheMangerEx.getApplicationInfoAsUser(HwApiCacheMangerEx.java:145)
      at android.app.ApplicationPackageManager.getApplicationInfoAsUser(ApplicationPackageManager.java:417)
      at android.app.ApplicationPackageManager.getApplicationInfo(ApplicationPackageManager.java:409)
      at pt.a(:com.google.android.gms.dynamite_mapsdynamite@17122079@17.1.22 (100306-245988633):3)
      at com.google.maps.api.android.lib6.drd.r.b(:com.google.android.gms.dynamite_mapsdynamite@17122079@17.1.22 (100306-245988633):15)
      at com.google.maps.api.android.lib6.impl.fl.a(:com.google.android.gms.dynamite_mapsdynamite@17122079@17.1.22 (100306-245988633):50)
      at com.google.maps.api.android.lib6.impl.fk.a(:com.google.android.gms.dynamite_mapsdynamite@17122079@17.1.22 (100306-245988633):4)
      at com.google.maps.api.android.lib6.impl.fm.run(:com.google.android.gms.dynamite_mapsdynamite@17122079@17.1.22 (100306-245988633):4)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
      at java.lang.Thread.run(Thread.java:784)
  Caused by: android.os.DeadSystemException
      ... 11 more
  </code></pre>
  
  <p>For Samsung:</p>
  
  <pre><code>java.lang.RuntimeException: android.os.DeadSystemException
      at android.app.ApplicationPackageManager.getPackageInfoAsUser(ApplicationPackageManager.java:264)
      at android.app.ApplicationPackageManager.getPackageInfo(ApplicationPackageManager.java:237)
      at pt.b(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):4)
      at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):58)
      at com.google.android.gms.maps.internal.CreatorImpl.newMapViewDelegate(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):29)
      at com.google.android.gms.maps.internal.h.a(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):62)
      at hj.onTransact(:com.google.android.gms.dynamite_mapsdynamite@17122081@17.1.22 (100400-245988633):4)
      at android.os.Binder.transact(Binder.java:675)
      at com.google.android.gms.internal.maps.zza.a(zza.java:7)
      at com.google.android.gms.maps.internal.zzf.a(zzf.java:11)
      at com.google.android.gms.maps.MapView$zzb.a(MapView.java:31)
      at com.google.android.gms.dynamic.DeferredLifecycleHelper.a(DeferredLifecycleHelper.java:44)
      at com.google.android.gms.dynamic.DeferredLifecycleHelper.a(DeferredLifecycleHelper.java:5)
      at com.google.android.gms.maps.MapView.a(MapView.java:22)
      at com.myapp.myapp.viewholder.MyViewHolder.E(MyViewHolder.java:3)
      at com.myapp.myapp.viewholder.MyViewHolder.A(MyViewHolder.java:6)
      at com.myapp.myapp.viewholder.MyViewHolder.&lt;init&gt;(MyViewHolder.java:159)
      at com.myapp.myapp.activities.MyActivity$18.a(MyActivity.java:55)
      at com.myapp.myapp.adapter.MyAdapter.a(MyAdapter.java:8)
      at android.support.v7.widget.RecyclerView$Adapter.b(RecyclerView.java:5)
      at android.support.v7.widget.RecyclerView$Recycler.a(RecyclerView.java:293)
      at android.support.v7.widget.RecyclerView$Recycler.a(RecyclerView.java:5)
      at android.support.v7.widget.RecyclerView$Recycler.c(RecyclerView.java:1)
      at android.support.v7.widget.LinearLayoutManager$LayoutState.a(LinearLayoutManager.java:11)
      at android.support.v7.widget.LinearLayoutManager.generateDefaultLayoutParams(LinearLayoutManager.java:0)
          onDetachedFromWindow(LinearLayoutManager.java:0)
          onInitializeAccessibilityEvent(LinearLayoutManager.java:0)
          onRestoreInstanceState(LinearLayoutManager.java:0)
          setStackFromEnd(LinearLayoutManager.java:0)
          smoothScrollToPosition(LinearLayoutManager.java:0)
          onLayoutCompleted(LinearLayoutManager.java:0)
          onAnchorReady(LinearLayoutManager.java:0)
          updateAnchorInfoForLayout(LinearLayoutManager.java:0)
          updateAnchorFromPendingData(LinearLayoutManager.java:0)
          fixLayoutEndGap(LinearLayoutManager.java:0)
          updateLayoutStateToFillEnd(LinearLayoutManager.java:0)
          scrollHorizontallyBy(LinearLayoutManager.java:0)
          updateLayoutState(LinearLayoutManager.java:0)
          collectPrefetchPositionsForLayoutState(LinearLayoutManager.java:0)
          collectInitialPrefetchPositions(LinearLayoutManager.java:0)
          collectAdjacentPrefetchPositions(LinearLayoutManager.java:0)
          assertNotInLayoutOrScroll(LinearLayoutManager.java:0)
          recycleChildren(LinearLayoutManager.java:0)
          recycleViewsFromStart(LinearLayoutManager.java:0)
          recycleByLayoutState(LinearLayoutManager.java:0)
          fill(LinearLayoutManager.java:0)
          layoutChunk(LinearLayoutManager.java:0)
          findFirstVisibleChildClosestToStart(LinearLayoutManager.java:0)
          findReferenceChild(LinearLayoutManager.java:0)
          findOneVisibleChild(LinearLayoutManager.java:0)
          onFocusSearchFailed(LinearLayoutManager.java:0)
          prepareForDrop(LinearLayoutManager.java:0)
      at android.support.v7.widget.LinearLayoutManager.a(LinearLayoutManager.java:44)
      at android.support.v7.widget.LinearLayoutManager.c(LinearLayoutManager.java:394)
      at android.support.v7.widget.RecyclerView.O(RecyclerView.java:38)
      at android.support.v7.widget.RecyclerView.q(RecyclerView.java:37)
      at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:5)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
      at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.support.design.widget.CoordinatorLayout.d(CoordinatorLayout.java:143)
      at android.support.design.widget.CoordinatorLayout.a(CoordinatorLayout.java:32)
      at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:48)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
      at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
      at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
      at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
      at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
      at com.android.internal.policy.DecorView.onLayout(DecorView.java:1041)
      at android.view.View.layout(View.java:22407)
      at android.view.ViewGroup.layout(ViewGroup.java:6579)
      at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3357)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2826)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1874)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8491)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
      at android.view.Choreographer.doCallbacks(Choreographer.java:761)
      at android.view.Choreographer.doFrame(Choreographer.java:696)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
      at android.os.Handler.handleCallback(Handler.java:873)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:214)
      at android.app.ActivityThread.main(ActivityThread.java:7058)
      at java.lang.reflect.Method.invoke(Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:964)
  Caused by: android.os.DeadSystemException
      ... 84 more
  </code></pre>
  
  <p>The map is implemented like this:</p>
  
  <p>View holder layout (simplified):</p>
  
  <pre><code>&lt;com.google.android.gms.maps.MapView
      android:id="@+id/map"
      android:layout_width="@dimen/_100sdp"
      android:layout_height="@dimen/_100sdp"
      android:visibility="gone"
      map:liteMode="true"
      map:mapType="none" /&gt;
  </code></pre>
  
  <p>View Holder (simplified):</p>
  
  <pre><code>public class MyHolder extends RecyclerView.ViewHolder implements OnMapReadyCallback {
  
      private @NonNull MapView mapView;
      private @Nullable Location location;
  
      public MyHolder(@NonNull View itemView) {
          super(itemView);
  
          mapView = itemView.findViewById(R.id.map);
          mapView.onCreate(null);
          mapView.getMapAsync(this);
  
          LocalBroadcastManager.getInstance(App.getInstance().getApplicationContext()).registerReceiver(broadcastReceiver, new IntentFilter(MyFilter));
      }
  
      // Called when the view holder is recycled
      public void recycle() {
  
          mapView.setVisibility(View.GONE);
          releaseMap();
      }
  
      // Called when binding the view holder or by the broadcast receiver
      public void update(@NonNull Location location) {
          this.location = location;
  
          mapView.setVisibility(View.VISIBLE);
          setMapLocation();
      }
  
      @Override
      public void onMapReady(GoogleMap googleMap) {
  
          MapsInitializer.initialize(App.getInstance().getApplicationContext());
          map = googleMap;
          map.getUiSettings().setMapToolbarEnabled(false);
          map.getUiSettings().setAllGesturesEnabled(false);
  
          setMapLocation();
      }
  
      private void setMapLocation() {
  
          if (map == null) {
              return;
          }
  
          if (location == null) {
              map.setMapType(GoogleMap.MAP_TYPE_NONE);
              return;
          }
  
          LatLng mapLocation = new LatLng(location.getLatitude(), location.getLongitude());
          map.addMarker(new MarkerOptions().position(mapLocation));
          map.moveCamera(CameraUpdateFactory.newLatLngZoom(mapLocation, 14f));
          map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
      }
  
      private void releaseMap() {
  
          if (map == null) {
              return;
          }
  
          map.clear();
          map.setMapType(GoogleMap.MAP_TYPE_NONE);
      }
  
      private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
  
              update();
          }
      };
  }
  </code></pre>
  
  <p>What can be the cause of this?</p>