Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 773
ForeverLearning Avatar asked Jan 11 '15 03:01

ForeverLearning


People also ask

How do I get Google Maps Key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key.

Why does my Google Maps not working?

Clear the app's cache & data On your Android phone or tablet, open the Settings app . Tap Apps & notifications. Follow the steps on your device to find the Maps app. After you select the app, storage & cache options should be available.

How do you refresh Google Maps?

Tap "Updates," located in the bottom-right corner of the screen. 3. If you see the Maps app listed there, tap "Get Updates" next to it. 4.


1 Answers

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.

like image 52
stkent Avatar answered Sep 20 '22 08:09

stkent