lionheart lionheart - 1 year ago 145
Android Question

Google Maps crash during APK build execution

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):

10-19 12:17:27.244 2256-2638/ E/BaseAppContext: Tried to stop global GMSCore RequestQueue. This is likely unintended, so ignoring.
10-19 12:17:28.640 1921-1921/ E/BluetoothAdapter: Bluetooth binder is null
10-19 12:17:29.537 1921-1921/ E/BluetoothAdapter: Bluetooth binder is null
10-19 12:17:29.542 2256-2677/ 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/ E/ChimeraRcvrProxy: Can't find Chimera receiver impl class, dropping broadcast
10-19 12:17:31.602 2393-2501/ 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/ 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/ E/Surface: getSlotFromBufferLocked: unknown buffer: 0xae4428c0
10-19 12:17:48.704 2393-2769/ E/UncaughtException: java.lang.AssertionError
                                                                       at$a.(Unknown Source)
                                                                       at$19.a(Unknown Source)
                                                                       at Source)
                                                                       at Source)
                                                                       at Source)
                                                                       at Source)
                                                                       at Source)
                                                                       at$1.(Unknown Source)
                                                                       at Source)
                                                                       at Source)

As stated in here, I'm declaring the API keys in build gradle:
Google Maps Signed APK Android

Code sample of how I initialize the map:

public class MainMapFragment extends BaseFragment implements{...
public void onCreate(Bundle savedInstanceState) {
Log.d(Consts.TAGS.FRAG_MAIN_MAP,"BEGIN onCreate()");

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(, _mapFragment).commit();
public void onMapReady(GoogleMap googleMap) {
Log.d(Consts.TAGS.FRAG_MAIN_MAP,"BEGIN onMapReady()");
_map = googleMap;
_map.setInfoWindowAdapter(new CDInfoWindowAdapter(getActivity(),_markersPos));
_map.setPadding(120, 120, 170, 200);


and this is the Fragment layout:

<RelativeLayout tools:context=".MainMapFragment"

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

Answer Source

What's I've done in order to correct it (because the app is not ready for production and Google APIs & SDKs try to use a key that is not relevant to the apk build type) is configuring gradle build to work as I expected it to work:

    buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
    debug {
        minifyEnabled false
        **debuggable true**
        proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
        resValue "string", "google_maps_api_key", "***************"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download