31

I'm having major troubles getting Google Maps working in production within an Android app. This is what I am currently getting (the bottom is just ads).

App production screen

Key Steps I have followed:

1) I have ensured I have got the correct SHA1 Production Key and have implemented it on the Google Console API as well as within the app (They key that google gives). I have registered two keys - one for the debug and one for production

2) Internet, location, etc is working

3) The app works in DEBUG mode, but does not work when signed and installed on device via USB. I have triple checked the SHA 1 signature of the sign, etc.

4) The MapsFragment comes from the template available in Android Studio.

In production mode, the log cat displays this:

01-11 16:04:54.511  19346-19437/com.mike.mapstest E/Google Maps Android API﹕ Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-11 16:04:54.516  19346-19437/com.mike.mapstest E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
    Ensure that the "Google Maps Android API v2" is enabled.
    Ensure that the following Android Key exists:
    API Key: YOUR_KEY_HERE
    Android Application (<cert_fingerprint>;<package_name>): <SHA1 Removed for this> ;com.mike.mapstest

This error obviously says something is wrong with my auth? What am I doing wrong?

stkent
  • 18,470
  • 14
  • 80
  • 99
ForeverLearning
  • 1,027
  • 1
  • 12
  • 26

8 Answers8

48

Based on the logcat output from your debuggable release build:

01-11 16:04:54.511  19346-19437/com.mike.mapstest E/Google Maps Android API﹕ Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-11 16:04:54.516  19346-19437/com.mike.mapstest E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
    Ensure that the "Google Maps Android API v2" is enabled.
    Ensure that the following Android Key exists:
    API Key: YOUR_KEY_HERE
    Android Application (<cert_fingerprint>;<package_name>): <SHA1 Removed for this> ;com.mike.mapstest

it would appear that you have not overridden the api key placeholder YOUR_KEY_HERE in the manifest (or separate api keys file, depending on your configuration). Replace that string, wherever it lives, with your actual key and you should be good to go.

Edit: this tutorial, if it matches your configuration, probably explains why you are only seeing this for release builds:

Return to Android Studio and paste the API key into the YOUR_KEY_HERE section of the file:

Note that these steps have enabled Google Maps support for the debug version of the application package. The API key will also need to be added to the google_maps_api.xml file located in MapDemo -> app -> src -> release -> res -> values when the release version of the application is ready to be built.

Community
  • 1
  • 1
stkent
  • 18,470
  • 14
  • 80
  • 99
  • 6
    Thanks @stkent. This was the issue. It appears one must hardcode the API key into the manifest rather than using a string resource from an external XML file. – ForeverLearning Jan 11 '15 at 21:33
  • Exact same problem and this was the fix. I will repeat: you MUST hardcode the API key in the manifest! – Tys Feb 17 '15 at 06:28
  • @ForeverLearning I am having the same problem, but still after hardcoding in manifest, no luck :( – Narendra Singh Nov 04 '15 at 08:49
  • 1
    Same issu here, but no hardcoding solve it. Nevertheless, when I'm writing this comment, there is NO "Google Maps Android API v2" on Google Console, just "Google Maps Android API". Is it the same? – Karoly Mar 21 '16 at 23:06
  • 2
    Ok, I've found the solutions. First: The key has to be hardcoded Second: When I generated the KEY I used key;packagename template, what the Android studio generated to me on the comment section at google_maps_api.xml . Yeah... THE PACKAGE NAME BELONGS TO THE FRAGMENT, AND NOT THE MAINFEST PACKAGE. This killed everything, when I switch it with the one from the manifest, it was OK. Make sure you using the key;manifestpackage template on the GoogleConsole when generating your API key @DroidWormNarendra – Karoly Mar 21 '16 at 23:19
  • 1
    For some reason, generating the API Key from the link provided in the comments doesn't work (well, didn't for me). Instead, generating the key from [here](https://developers.google.com/maps/documentation/android-api/signup) did. Just follow the instructions and you should be good to go. – Ivan Feb 13 '18 at 02:29
9

I was having these same issues, and was banging my head against the wall for a few days. I read all the posts about putting the correct key in place. I kept putting the correct key in my google_maps_api.xml file. StKent above mentioned to make sure to overwrite with the actual string in AndroidManifest.xml. This is what fixed it for me.

What I had when it didn't work: in AndroidManifest.xml:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

and in google_maps_api.xml:

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

What I changed to for it to work I changed my AndroidManifest.xml to include:

<meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="AIzsa_the actual key" />
Chris Toews
  • 119
  • 1
  • 3
  • 1
    Yeah, @StKent was the right answer, need to hardcode it. Caused me so much frustration when I did it following the actual proper documentation. – ForeverLearning Jan 25 '16 at 20:18
  • I hardcoded debug API_KEY for tag com.google.android.geo.API_KEY in manifest.xml, but still its not working. FYI it was working properly yesterday, but suddenly stopped showing up map layer, showing just Google icon in bottom|left – umesh Aug 22 '17 at 06:26
4

debug and production key will be different . If you use debug key for release mode ,you can not view the google map. For release mode , when you change google map key , you should clean the project then export apk.

you can get more information https://developers.google.com/maps/documentation/android/start

to get private SHA1 from debug key store

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass your_app_password

to see more

SHA-1 fingerprint of keystore certificate

or you can you eclipse tool to generate private SHA1 key using export menu

Community
  • 1
  • 1
Mohammod Hossain
  • 4,024
  • 2
  • 23
  • 34
4

When using Android Studio to generate the Google Maps Activity, it will ignore your gradle build configs and use the default debug.keystore. The SHA1 in google_maps_api.xml is based off of this default. When creating permission in the Google API console, make sure to use your production and debug SHA1 if you are using the non default.

Steve Tauber
  • 7,905
  • 5
  • 37
  • 44
  • Good to know! I have not used the Android Studio maps activity generator yet. – stkent Jan 22 '16 at 14:59
  • The language of your answer is somewhat unclear. Which keystore should be used to generate the SHA-1 hash to be entered into the Google console? – Tim Biegeleisen Jul 10 '18 at 15:43
  • @TimBiegeleisen this was from many versions ago so it might no longer be valid; however, when using Android Studio's function to generate the Google Maps Activity, it would never use your production configuration. In Google console, if you are setting it up for production you should use the SHA1 for production keystore. I'm suggesting your Google console should have both debug AND production so your test builds work. – Steve Tauber Jul 10 '18 at 18:26
1

In my case, I had entered the wrong package name in Google API's API Manager - Credentials - "Restrict usage to your Android apps". Make sure you enter the correct package name (as in AndroidManifest.xml) and the correct SHA fingerprints (for debug and production). Google API Manager Screenshot

stefan.m
  • 1,612
  • 3
  • 17
  • 34
0

Solved, I put on the Manifest the "Key for browser apps (with referers)" instead of the "Key for Android apps (with certificates)" from the Google API Console

0

In my case, the gray screen was caused by having a custom implementation of HostnameVerifier that was preventing the tiles from being loaded.

Hope this will help someone else in the future.

Adrian C.
  • 1,446
  • 1
  • 21
  • 27
-1

error //Ensure that the "Google Maps Android API v2" is enabled. In this u can't find like Google Maps Android API v2 in Google Cloud Platform Console.in this, give the exact Package Name: and signature of your project which is showing in run window or debug window , I faced the same problem because of changing MapActivity package location I struggled to find this whole day so make sure whether u changed any packages inside project if so give package which is showing in error text emphasized text Ensure that the following Android Key exists: API Key: YOUR_KEY_HERE Android Application (;): ;com.mike.mapstest

Aravinth
  • 1
  • 1