Google Maps API Authorization Error - Getting Round It
Guide
Stuck with Google Maps on Android? Look no further, here is a guide on how to win the war against the ARM EABI v7a System Image and Google API’s!
Old Article
This content may be out of date or broken, please take care.Okay, so this took me forever to figure out – not helping is the fact I am a total newb when it comes to Android development… I don’t even have an Android phone!
So before I begin with this guide let me lay down some scope: it should be able to get Google Maps working in the GenyMotion emulator – I gave up using the ADT emulators as they were far too slow. For this guide, I am going to use the Google Map API demo, they have code that works and this is all about the setup. Furthermore, I have done this in Windows 8, so if you have another OS, you’ll have to do some smart thinkin’. You’re going to need a google account too, if you haven’t already got one. Without further ado, let us step boldly into the unknowns of Android cartography – ironic eh?
Android SDK, I am going to assume you have this on your machine and have done some vagaries of android development. If you don’t, fear not! Here is the whole package, it has Eclipse too.
Next up, we’re going to want to get the GooglePlay API setup. It comes part and parcel with the Android SDK, the only thing you need to do is install its package. Google have a guide if you get stuck, but the gist is:
-
In Eclipse, Window>Android SDK Manager
-
You’re going to want to check Android #.# (API #)> SDK Platform, ARM EABI v7a System Image and Google API’s. That is three packages in the version you want to use – the demo is for Android 4.4 (API 19).
-
You also need to check Extras > Google Play Services and Google Repository.
Taming the beast that is an API Key is next on our to-do list, and we’re going to use CMD to do it. Open command prompt: Windows Key + R>"cmd">Hit enter.
-
You’re going to want to navigate to where your JDK has been installed eg. In CMD type: “cd “C:\Program Files\Java\jdk1.7.0_45\bin" “ then press enter.
-
Here we will use the Java keytool.exe to extract our API key. To do this, you will need to know where your debug.keystore file is. You will most likely find this here: %userprofile%\.android\debug.keystore
-
When you know that enter this into CMD: “keytool -v -list -alias androiddebugkey –keystore "%userprofile%\.android\debug.keystore" -storepass android -keypass android"
-
You’re looking to get a load of info back, specifically the certificate finger print, SHA1. When you find that, you will need to copy it.
-
Next you need to go to the Google API Console.
-
Create a new project, call it whatever you like.
-
Register your app, choose Android as the platform, then enter its package name. For this demo it will be “com.example.mapdemo", then paste in the SHA1 key you copied earlier.
-
This will return you an API key. Take a note of this.
If you have any problems with this step, you can get the google guide here.
Before we go any further let’s get the map demo source. You can find it in the ADT package: \sdk\extras\google\google_play_services\samples\maps
We’re going to want to modify the manifest of the map demo with our API key. Around line 33 in the Manifest of the demo you will find meta-tag with a value. Replace that value with your key – you can’t use the key that is already there.
Here is where Google support stops, and you find that stuff isn’t quite working still? Alas, I have done the research and googling for you! Firstly, you need to hit up the Google API Console again, and you’re going to want to turn on the “Google Maps Android API v2".
Next, you will need double check that your project.propeties has the following line (it should): android.library.reference.1=google-play-services_lib
Next, a setting in proguard-project.txt needs to be appended:
-keep class * extends java.util.ListResourceBundle {protected Object[][] getContents();
}
Stackoverflow user Rusfearuth explains this point (with pics) for this question.
Finally, we need to fix up your emulator. Like I said earlier, I used GenyMotion, you can download it free (for personal use) when you register. They have an easy to follow guide, which will walk you through all the steps for setup and use here.
For the Maps API to work with GenyMotion you need to add/install two files.
-
Open a GenyMotion Emulator.
-
Download ARM Translation Installer v.1.1.
-
Download Google Apps for Android 4.3.
-
Drag and drop each file onto the Emulator, when it asks you about flash click Ok, after it finishes reboot. Then rinse repeat for the 2nd file. Stackoverflow user japzone answers this question with detailed steps for this.
-
Download ARM Translation Installer v.1.1.
To test that Google Play is working, run the emulator, find it in the installed apps, and search for any android app – like SnapChat, if it works, you’re spot on.
Once all these steps have been completed it should work, if it dosen’t it could be because you need to uninstall your app to clear out the cache. As far as I am aware, this won't work in the ADT Emulator, at least there is another step involved somewhere.