Google Maps crash during APK build execution
<p>I'm using Google Map in my app. I've tried to use MapView as well as SupportMapFragment inside a Fragment that contains the Map.
The issue that comes up causes Google Maps to crash after 'Build APK' process (in all devices that I've tested) during map initialization, but when running from Android Studio (with Run) it works as expected. This is the stack trace (all I get in all executions is AssertionError):</p>

<blockquote>
  <p>10-19 12:17:27.244 2256-2638/com.google.android.gms E/BaseAppContext: Tried to stop global GMSCore RequestQueue. This is likely unintended, so ignoring.
  10-19 12:17:28.640 1921-1921/com.google.android.gms.persistent E/BluetoothAdapter: Bluetooth binder is null
  10-19 12:17:29.537 1921-1921/com.google.android.gms.persistent E/BluetoothAdapter: Bluetooth binder is null
  10-19 12:17:29.542 2256-2677/com.google.android.gms E/MDM: [142] rpv.a: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null, message=null}
  10-19 12:17:30.112 1921-1921/com.google.android.gms.persistent E/ChimeraRcvrProxy: Can't find Chimera receiver impl class com.google.android.gms.auth.setup.devicesignals.LockScreenChimeraReceiver, dropping broadcast
  10-19 12:17:31.602 2393-2501/com.app E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa112310
  10-19 12:17:36.351 2776-2782/? E/art: Failed sending reply to debugger: Broken pipe
  10-19 12:17:37.267 1269-1617/? E/SurfaceFlinger: ro.sf.lcd_density must be defined as a build property
  10-19 12:17:46.449 1269-1269/? E/EGL_emulation: tid 1269: eglCreateSyncKHR(1370): error 0x3004 (EGL_BAD_ATTRIBUTE)
  10-19 12:17:47.050 2393-2501/com.app E/Surface: getSlotFromBufferLocked: unknown buffer: 0xaa112700
                                                           
                                                           [ 10-19 12:17:47.094  2393: 2842 D/         ]
                                                           HostConnection::get() New Host Connection established 0xb4050b90, tid 2842
  10-19 12:17:47.222 1899-2797/com.android.inputmethod.latin E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae4428c0
  10-19 12:17:48.704 2393-2769/com.app E/UncaughtException: java.lang.AssertionError
                                                                         at com.google.a.b.a.m$a.(Unknown Source)
                                                                         at com.google.a.b.a.m$19.a(Unknown Source)
                                                                         at com.google.a.f.a(Unknown Source)
                                                                         at com.google.a.b.a.b.a(Unknown Source)
                                                                         at com.google.a.f.a(Unknown Source)
                                                                         at com.google.a.b.a.i.a(Unknown Source)
                                                                         at com.google.a.b.a.i.a(Unknown Source)
                                                                         at com.google.a.b.a.i$1.(Unknown Source)
                                                                         at com.google.a.b.a.i.a(Unknown Source)
                                                                         at com.google.a.b.a.i.a(Unknown Source)
   </p>
</blockquote>

<p>As stated in here, I'm declaring the API keys in build gradle:
<a href="https://stackoverflow.com/questions/30298223/google-maps-signed-apk-android">Google Maps Signed APK Android</a></p>

<p>Code sample of how I initialize the map:</p>

<pre><code>public class MainMapFragment extends BaseFragment implements{...
    @Override
public void onCreate(Bundle savedInstanceState) {
    Log.d(Consts.TAGS.FRAG_MAIN_MAP,"BEGIN onCreate()");
    super.onCreate(savedInstanceState);

    FragmentManager fm = getChildFragmentManager();
    _mapFragment = (SupportMapFragment) fm.findFragmentByTag(Consts.TAGS.UTIL_MAP);
    if (_mapFragment == null) {
        Log.d(Consts.TAGS.FRAG_MAIN_MAP,"mapFragment is null. creating new map...");
        _mapFragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.map_container, _mapFragment).commit();
        _mapFragment.getMapAsync(this);
    }
@Override
public void onMapReady(GoogleMap googleMap) {
    Log.d(Consts.TAGS.FRAG_MAIN_MAP,"BEGIN onMapReady()");
    _map = googleMap;
    //_map.setInfoWindowAdapter(this);
    _map.setInfoWindowAdapter(new CDInfoWindowAdapter(getActivity(),_markersPos));
    _map.setOnInfoWindowClickListener(this);
    _map.setPadding(120, 120, 170, 200);
    MapsInitializer.initialize(getActivity());        
    initilizeMap();
}

}
</code></pre>

<p>and this is the Fragment layout:</p>

<pre><code>&lt;RelativeLayout tools:context=".MainMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map_container"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"&gt;
 &lt;!--&lt;fragment--&gt;
        &lt;!--android:id="@+id/map"--&gt;
        &lt;!--android:name="com.google.android.gms.maps.SupportMapFragment"--&gt;
        &lt;!--android:layout_width="match_parent"--&gt;
        &lt;!--android:layout_height="match_parent"--&gt;
        &lt;!--/&gt;--&gt;
 &lt;!--&lt;com.google.android.gms.maps.MapView--&gt;
     &lt;!--xmlns:android="http://schemas.android.com/apk/res/android"--&gt;
     &lt;!--android:layout_width="match_parent"--&gt;
     &lt;!--android:layout_height="match_parent"--&gt;
     &lt;!--android:id="@+id/map_view"--&gt;
     &lt;!--/&gt;
--&gt;
&lt;/RelativeLayout&gt;
</code></pre>

<p>What can be the issue if the code works in Run mode but not in 'Build APK' mode?</p>