Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
287 views
in Technique[技术] by (71.8m points)

android - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...