Blog

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!

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?

1.

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.

2.

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:

  1. In Eclipse, Window>Android SDK Manager

  2. 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).

  3. You also need to check Extras > Google Play Services and Google Repository.

3.

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.

  1. 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.

  2. 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

  3. When you know that enter this into CMD: “keytool -v -list -alias androiddebugkey –keystore "%userprofile%\.android\debug.keystore" -storepass android -keypass android"

  4. 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.

  5. Next you need to go to the Google API Console.

  6. Create a new project, call it whatever you like.

  7. 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.

  8. 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.

4.

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

5.

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.

6.

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

7.

Next, you will need double check that your project.propeties has the following line (it should): android.library.reference.1=google-play-services_lib

8.

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.

9.

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.

10.

For the Maps API to work with GenyMotion you need to add/install two files.

  1. Open a GenyMotion Emulator.

  2. Download ARM Translation Installer v.1.1.

  3. Download Google Apps for Android 4.3.

  4. 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.

  5. Download ARM Translation Installer v.1.1.

11.

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.

Comments