Release APK file not showing google maps

if any one still facing this problem :

this happend to me because we need two google maps api keys one for the debug and another one for the release, you can check in :

C:\Users\username\AndroidStudioProjects\yourapp\app\src\ debug \res\values and you'll find an xml with your api key like:

    <string name="google_maps_key" templateMergeStrategy="preserve" 
          translatable="false">AIza...etc</string>

but if you check here:

C:\Users\username\AndroidStudioProjects\yourapp\app\src\ release \res\values you will find an xml but without api key inside like:

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

it was noted as a comment inside the xml file itself :

Before you release your application, you need a Google Maps API key.

To do this, you can either add your release key credentials to your existing
key, or create a new key.

Note that this file specifies the API key for the release build target.
If you have previously set up a key for the debug target with the debug signing certificate,
you will also need to set up a key for your release certificate.

Follow the directions here:

https://developers.google.com/maps/documentation/android/signup

Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.

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

enter image description here

Remember to make Build Type --- release

enter image description here

  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

enter image description here

Generate APK using keystore and enjoy your map


It might be silly but I had my API key included in

app\src\debug\res\values\google_maps_api.xml (debug)

You also need to include in-

app\src\release\res\values\google_maps_api.xml (release)