Reputation: 286
I got a sample application from Xamarin which is a simple application which shows Google Maps
. I have got the API
key using the SHA1
fingerprint which I got from Eclipse and package name which I got from AndroidManifest.XML
.
Every time I load the map, I get an error:
06-11 12:41:24.852 I/Google Maps Android API(16453): Failed to contact Google servers. Another attempt will be made when connectivity is established.
06-11 12:41:24.862 E/Google Maps Android API(16453): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
I have no connection issue therefore I'm thinking there is some kind of issue with my API key.
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="GooglePlayServicesTest.GooglePlayServicesTest">
<uses-sdk android:minSdkVersion="8" />
<application android:label="GooglePlayServicesTest" android:icon="@drawable/icon">
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="MY API KEY" />
</application>
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /></manifest>
Layout xml file
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Any help would be appreciated. Thanks in advance
Upvotes: 2
Views: 3691
Reputation: 1066
I had the same problem, carefully follow instructions from Xamarin Documentation, forums and make each one of the steps listed by @elMarquis answer. Nothing worked.
It turned out that Google Play Console may be signing your released apk with its own certificate, creating a different SHA1 signature that not match with the one you are using, and of course, with the one that you setup in Google Developer Console for the Google Maps API on Android. So, in your Google Play Console watch out for Release Management>App Signing. There is the SHA1 fingerprint that you must use to authorize in your Google Developer Console.
Upvotes: 0
Reputation: 7730
You need to make sure the SHA1 fingerprint is whitelisted for the Maps API key you are using for both the debug keystore file and the release keystore file.
When adding your map to your app during development, most likely you will have followed this xamarin tutorial:
Which directs you to here for details on obtaining an API Key, and how to whitelist your SHA1 identifiers.
Basically it tells you to find the SHA1 fingerprint of the existing xamarin debug keystore file. This is done by running the following on the terminal:
keytool -list -v -keystore [STORE FILENAME] -alias [KEY NAME] -storepass [STORE PASSWORD] -keypass [KEY PASSWORD]
When it's debug STORE FILENAME will be: /Users/[USERNAME]/.local/share/Xamarin/Mono\ for\ Android/debug.keystore
When you come to release your app you need to generate a new Keystore file for release. It tells you about it here:
You need to run that same keytool -list command as above only this time the STORE FILENAME will be the filename of the keystore file you just generated.
In the Google API console you can add multiple SHA fingerprints to a single API key by having them on seperate lines.
01:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;mypackage.name
01:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX;mypackage.name
As long as the SHA1 from both keystore files is on that list your map should work on both debug and release.
Upvotes: 2
Reputation: 286
As I'm running this application on an android device, I used the "Key for Android apps (with certificates)" from Google which didn't work.
I used the "Key for browser apps (with referers)" and it worked for some reason.
Upvotes: 0
Reputation: 1511
The first think I would do is double check that the API key you got the SHA1 fingerprint from is indeed the API key that is used to sign the application. Xamarin.Android has it's own debug.keystore
which might be different than what Eclipse is using.
One trick (and this is kind of backwards) to ensuring you have the correct SHA1 fingerpring is to unzip your APK file, then use keytool
to find the SHA1 fingerprint (it's in META-INF/ANDROIDD.RSA
). Something like this:
$ unzip MyAndroidApp.APK -d MyAndroidApp
$ keytool -printcert -file MyAndroidApp/META-INF/ANDROIDD.RSA
Upvotes: 0
Reputation: 559
use this in manifest file
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="ur api key" />
Upvotes: 0