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 ingoogle_maps_api.xml
orAndroidManifest.xml
- Make sure
Package name
andSHA-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>