Google Maps Android API v2 Authorization failure
Steps:
- to ensure that device has Google Play services APK
- to install Google Play Service rev. more than 2
- to create project at https://code.google.com/apis/console/
- to enable "Google Maps Android API v2"
- to register of SHA1 in project (NOW, YOU NEED WRITE SHA1;your.app.package.name) at APIs console and get API KEY
- to copy directory ANDROID_SDK_DIR/extras/google/google_play_services/libproject/google-play-services_lib to root of your project
- to add next line to the YOUR_PROJECT/project.properties
android.library.reference.1=google-play-services_lib
- to add next lines to the
YOUR_PROJECT/proguard-project.txt
.
-keep class * extends java.util.ListResourceBundle {
protected Object[][] getContents();
}
Now you are ready to create your own Google Map app with using Google Map APIs V2 for Android.
If you create application with min SDK = 8, please use android support library v4 + SupportMapFragment instead of MapFragment.
Google Maps Android API: Authorization failure. Ensure that the Google Maps Android API v2 is enabled. Ensure that the following Android Key exists
I followed this tutorial and I was able to fix it: https://www.youtube.com/watch?v=sJBlQv6IptQ. The video makes references to this tutorial: http://ramsandroid4all.blogspot.com/2016/01/google-maps-android-example-in-android.html.
In my case, what I did was to create a new project at https://console.developers.google.com/. I used Android apps
for Application restrictions
:
For the Restrict usage to your Android apps
section, I had to provide a Package name
and a SHA-1 certificate fingerprint
. The Package name
was in my app/build.gradle
, specifically here:
applicationId "[my package name]"
The SHA-1 certificate fingerprint
I found it from Android Studio by running signingReport
:
The result included something like this:
Alias: AndroidDebugKey
MD5: [The value]
SHA1: [The value]
SHA-256: [The value]
Valid until: Wednesday, May 5, 2049
----------
BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed
16:31:44: Task execution finished 'signingReport'.
Now the map works correctly in my Android app:
UPDATE 1: To my surprise, the maps were working correctly only on the Android Studio Emulator but not on real Android physical devices. The solution was what I posted at https://stackoverflow.com/a/56307654/4242086.
Authorization failure with Google Maps Android API
The problem was located in local.properties:
Instead of MAPS_API_KEY="AbCdEfGhi1234..." it should read MAPS_API_KEY=AbCdEfGhi1234...
Don't surround the key with ""...
Android: Google Maps Android API: Authorization failure
After many hours, I figured out the answer plus one very important gotcha!
Situation
I need to re-explain as details I didn't know where important are actually paramount.
I inherited this project, so its history was unknown. Originally the program used the free version of Google Maps, which worked fine. Since this is a large company, they went ahead and paid for the full premium subscription service. Programmers added the new libraries and made the few code modifications to use those libraries.
But they still used the original (free) authorization key. This caused Google's servers to continue to treat the data as if it were a free version.
No one noticed this because the free Goole Maps API only has issues after some number (2500?) of API calls in one day. Our traffic only recently became high enough for this to be an issue. (After the limit, Google API sends an error message instead of data.)
Consequently any changes I made seemed to have no effect. And changing the keys in the code caused the authentication errors (see in question).
Solution
I had to make a new authentication key using the new premium libraries and console. This changed the Google server which of course caused all versions of the app already in existence to cease functioning!
The new authentication key, placed in the manifest, gets recognized by the Google API and everything works, yay! But we still need to release a new version in the Google Store.
Gotcha #1
The AndroidManifest.xml command that is listed in the docs DID NOT WORK:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AI............................mI"/>
This is the correct name that actually works:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AI............................mI" />
Gotcha #2
But when testing, I still got all sorts of errors. Why? because android devices maintain caches of the authentication keys. Clearing the data (or better, uninstalling) cleaned out those caches. Now everything works, yay.
Moral: when dealing with API keys, authentication, certificates, and anything similar, uninstall EVERY TIME! :)
Google maps v2: Authorization failure
Activate the Google Maps Android API v2
service in the Google API's console
. Also, after making changes do a full reinstall of the app on the device/emulator.
Google maps V2 - Authorization failure, I can't display map
SOLUTION:
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
Google Map Android API v2: Authorization Failure
Figured out my problem.
I've been generating keys from my release certificate, which WILL NOT WORK during debugging when I run the app on my phone. I have to use the debugging keystore certificate fingerprint instead.
Please remember to keep 2 keys:
Debug API key from your debugging keystore when you run it on your phone.
Release cert API key to be used when you want to sign the app just before deployment to Google Play Store.
Google Maps Android API Authorization failure - has this service changed in the last few months?
The answer from this question solved my problem with this. I had the exact same issue!
Google maps suddenly not working
Related Topics
Intercept Back Button from Soft Keyboard
Slowing Speed of Viewpager Controller in Android
How to Change Android Minsdkversion in Flutter Project
Startforeground Fail After Upgrade to Android 8.1
Remove Data from Notification Intent
What Are Advantages of Setting Largeheap to True
Android Studio - Mergedebugresources Exception
Android: Access Child Views from a Listview
Bitmapfactory Oom Driving Me Nuts
Don't Reload Application When Orientation Changes
What Characters Allowed in File Names on Android
Android: Remove Notification from Notification Bar
What Is the Size Limit for Logcat and How to Change Its Capacity