Android Google Maps Fail to Load on Release Build

July 21, 2018
SHA-1 signing-certificate fingerprint is included for signed apk

This article is related to Setup Android Google Maps (Google Play Version 15).

When Google Maps loades successfully on debug build but not release/signed apk, if could be due to Google API Console SHA-1 configuration or API Key configuration.

SHA-1 signing-certificate fingerprint for Google API console

Usually the first thing we suspect is did we include the SHA-1 signing-certificate fingerprint for the release build/signed apk?

Goto Google API console -> Credentials -> API keys. Check

  • API key matching the one in google_maps_api.xml or AndroidManifest.xml
  • Make sure Package name and SHA-1 certificate fingerprint is available for both debug and release build.

NOTE: Refer to Get SHA-1 Fingerprint Of Keystore Certificate

TIPS: You can build both debug and release with the same key. Refer to Android Studio Build Debug Apk With Release Key.

Missing google_maps_api.xml release configuraion

If you are using google_maps_api.xml, you might not realize there are actually 2 versions of the file at the following location

  • app/src/debug/res/values/google_maps_api.xml
  • app/src/release/res/values/google_maps_api.xml

NOTE: You will notice which build variant you are editing by seeing google_maps_api.xml (debug) in the Android project panel.

To edit the release version, Android Studio -> Build Variants (Left-lower corner), change to release build. You shall now see google_maps_api.xml (release).

Another way is to change Android to Project in Project panel and locate the files.

Store API Key in build.gradle with manifestPlaceholders

I prefer configure and store the api key in build.gradle (Module:app) file and discared the usage of google_maps_api.xml.

android {
    compileSdkVersion 27
    defaultConfig {
        ...
    }
    buildTypes {
        debug {
            manifestPlaceholders = [googleMapsKey: 'YOUR_API_KEY']

        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            manifestPlaceholders = [googleMapsKey: 'YOUR_API_KEY']
        }
    }
}

Edit AndroidManifest.xml.

<manifest ...>
    <application ...>
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="${googleMapsKey}" />
    </application>
</manifest>  
This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.