ForeverLearning
ForeverLearning

Reputation: 1037

Google Maps V2 not working in production with correct key

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?

Upvotes: 31

Views: 41505

Answers (8)

Aravinth
Aravinth

Reputation: 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

Upvotes: -1

Adrian C.
Adrian C.

Reputation: 1687

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.

Upvotes: 0

stkent
stkent

Reputation: 20128

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.

Upvotes: 49

Kodanda Devarakonda
Kodanda Devarakonda

Reputation: 1

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

Upvotes: 0

Mohammod Hossain
Mohammod Hossain

Reputation: 4114

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

Upvotes: 4

stefan.m
stefan.m

Reputation: 2012

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

Upvotes: 1

Chris Toews
Chris Toews

Reputation: 179

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" />

Upvotes: 12

Steve Tauber
Steve Tauber

Reputation: 10159

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.

Upvotes: 4

Related Questions