1

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

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{...
    @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();
}

}

and this is the Fragment layout:

<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">
 <!--<fragment-->
        <!--android:id="@+id/map"-->
        <!--android:name="com.google.android.gms.maps.SupportMapFragment"-->
        <!--android:layout_width="match_parent"-->
        <!--android:layout_height="match_parent"-->
        <!--/>-->
 <!--<com.google.android.gms.maps.MapView-->
     <!--xmlns:android="http://schemas.android.com/apk/res/android"-->
     <!--android:layout_width="match_parent"-->
     <!--android:layout_height="match_parent"-->
     <!--android:id="@+id/map_view"-->
     <!--/>
-->
</RelativeLayout>

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

Community
  • 1
  • 1
lionheart
  • 437
  • 11
  • 33

3 Answers3

2

You have headed to a wright way to get SHA-1 key for singed APK. I think, you should check registered keys on the developer console and put both keys over there: debug as well as release. If both are there look for the package name, make sure it is what defined within the manifest file. Then wait for few minutes until server get your keys configured. Hope it helps. Good Luck

Purvik Rana
  • 193
  • 2
  • 11
1

there seems to be a problem with your map key for your apk. Did you generate a new key for your package and your used key for building the apk?

Stephan Huewe
  • 124
  • 1
  • 7
  • You got it right, but the app is not ready for production. Therefore, I would prefer the answer I've added here. I think it's kind of obscure why google would prefer to use different API key (the one for production) during a debug build of apk. – lionheart Oct 30 '16 at 06:14
0

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'), 'proguard-rules.pro'
    }
    debug {
        minifyEnabled false
        **debuggable true**
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        resValue "string", "google_maps_api_key", "***************"
    }
}
lionheart
  • 437
  • 11
  • 33