Android Studio - Google Map Still Blank on Real Android Device on Release Apk

Android Google Maps is blank in Signed APK

Holly Molly, I ended up figuring out that the link in my dubug google_maps_api.xml contains the debug SHA-1 which it passes to Google Cloud Platform to whitelist the debug build for using the GoogleMaps api key that it will use.

This therefore means that if you build a release APK, the SHA-1 will be different.

How do you get the Release SHA-1? You do your Build->Generate Signed Bundle and follow the steps. Take note of where the .keystore file is saved. I used desktop.

Once you have done that, have a look at the screenshot in my question. It states using keytool -list ...etc to view the SHA-1 for the generated APK.

Once you have your SHA-1 showing, go to Google Cloud Platform, and into APIs, and into Maps SDK for Android. Click on the edit icon for the app that you wish to use the API for. You should now see a list titled API restrictions where there should be a list already containing the SHA-1 for your debug build.

Copy your SHA-1 from Terminal, (found by running that keytool -list ...etc) command. Paste it as a new 'item' in that Android app restrictions list. Save, if there is a save button.

You should be good to go from here on .


Or you could just un-restrict your API key usage, which is not recommended.

Android Studio - Google map still blank on real Android device on release apk

Make sure you enter your release API key in the google_maps_api.xml under the release folder.

First, switch to Project view by using the dropdown in the upper left of the Project Explorer. Then, expand app/src/, and you will see subfolders debug and release. Under there, you should see two separate google_maps_api.xml files under debug/res/values and release/res/values.

Make sure that the release API key is in the google_maps_api.xml file under the release/res/values folder, since this is the one that will be used for the signed release apk.

Sample Image

Google Maps not showing after debug and release APK

You need to add SHA-1 to Cloud Console project you are using the API in. For debug and unpublished release add the one you get from Android Studio after running signingReport.
If you are publishing the app and using Play Console signing you also need to add that SHA-1 as well.

Release APK file not showing google maps

Reason for this issue

This occurred because there are different SHA1s in debug and release types.

Fix for this issue

Add the SHA1 of the keystore used to build the release APK to Google console

Steps:

  1. Get the path of the keystore when you generate signed APK

    Build ----> Generate Signed APK..

Save the key store path

Sample Image

Remember to make Build Type --- release

Sample Image


  1. Extract SHA1 from the keystore.

Open your terminal use command below:

 keytool -list -v -keystore "/Users/NT/Desktop/generalkey.jks"

You will be asked for password for your keystore.

Change path to your keystore path keytool -list -v -keystore "keystore path"

From the Certificate fingerprints, you will see the SHA1


  1. Generate android key using this SHA1 and your package name

Sample Image

Generate APK using keystore and enjoy your map

Android Google Maps works on emulator but not on real device

I found the solution. Now fingerprint of release certificate is useless. To get map working you need to go to Google Play Console -> choose app -> Release management -> App signing and use fingerprint from App signing certificate.

Google Map not working in Release APK, but working correct in Debug APK

Debug certificate is different from your production certificate. You need to add both to your Google Maps key entry in your API console as seaparate row - each with the same packageId, but naturally different SHA1 hash.

OR

Maybe you have two google_maps_api.xml files, one in the app/src/debug/res/values folder and the other in the app/src/release/res/values folder, but only the debug one contains your API key.

Unable to view Maps with Debug/Release APK release

I was finally able to fix this issue and these were the steps I followed [on a windows machine, should be much more easier on a mac]:

a) cd into C:\Program Files\Java<jdk version>\bin [or wherever your jdk is installed].

b) Run: keytool -list -v -alias -keystore "{keystore ie., .jks file loc}" -storepass {your store password} -keypass {your keypass}

c) By running the keytool cmd, your SHA1 file would then be generated.

d) Login to https://console.developers.google.com/

e) In your project there will be a google_maps_api.xml file. In this file there is a commented url, something like this: https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r={your SHA1 key}%3B{your project package}.

f) In the link above, replace the default SHA1 key with the newely generated key and open the link on a browser from where you already have logged into google develover console.

h) Follow the steps as prompted on the browser and with this you should be able to generate an API key.

i) Paste the generated API key here:

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">API key</string>

This is available on your google_maps_api.xml file.

j) Now go to {your project location}\app\src\release\res\values and open the google_maps_api file. Here again, replace your API key in the location mentioned in point (i) ie., the code snippet.

k) Finally go to Android Studio > Your Project > Build > Generate Signed Bundle / APK > {input keystore path and passwords as per point (b)} > select debug/release version > Finish

The debug or release apk generated will now allow you to access google maps.



Related Topics



Leave a reply



Submit