Chris
Chris

Reputation: 5617

Google Play Services - Client Version vs Package Version

I have migrated my existing Android app to Android Studio / Gradle. I am now having problems with my Map, which was previously working.

I have cloned the android-maps-utils library from Google and added it to my project. I have added the dependency for android-map-utils to my gradle.build file.

When I load the screen that contains the Map, I get the following sequence from LogCat:

I/Google Maps Android API﹕ Google Play services client version: 5089000

I/Google Maps Android API﹕ Google Play services package version: 5089036

I/Google Maps Android API﹕ Failed to contact Google servers. Another attempt will be made when connectivity is established.

E/Google Maps Android API﹕ Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

I am going to go get a new Maps API Key, but I am curious if anyone thinks that the Google Play Services Client Version / Package Version difference could be causing a problem, and then how I could fix it?

Upvotes: 2

Views: 4189

Answers (1)

Mike
Mike

Reputation: 3732

The package version shown is newer than the client version, so in your case it is not a version compatibility issue.

Given that you already have an API key, the most likely causes in your case are either:

  1. You haven't registered the SHA-1 fingerprint of the signed app in your list of authorised apps for accessing your API key in the Google APIs console (you need to do this even for a debug-signed app)

or

  1. You haven't signed the app.

or

  1. Permissions are missing in the manifest:
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. They are required if you access the user's current location, either programmatically, or by enabling the My Location layer.-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

See the app signing / registration description in the getting started section for the Maps API: https://developers.google.com/maps/documentation/android/start#get_an_android_certificate_and_the_google_maps_api_key

Also, you could try adding the following code before loading the map to get more details on the access failure:

String googleError = null;
switch (MapsInitializer.initialize(ctx)) { // or GooglePlayServicesUtil.isGooglePlayServicesAvailable(ctx)
    case ConnectionResult.SERVICE_MISSING: googleError = "Failed to connect to google mapping service: Service Missing"; break;
    case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: googleError = "Failed to connect to google mapping service: Google Play services out of date. Service Version Update Required"; break;
    case ConnectionResult.SERVICE_DISABLED: googleError = "Failed to connect to google mapping service: Service Disabled. Possibly app is missing API key or is not a signed app permitted to use API key."; break;
    case ConnectionResult.SERVICE_INVALID: googleError = "Failed to connect to google mapping service: Service Invalid. Possibly app is missing API key or is not a signed app permitted to use API key."; break;
    case ConnectionResult.DATE_INVALID: googleError = "Failed to connect to google mapping service: Date Invalid"; break;
}
if (googleError != null)
    Log.d("MyApp", googleError);

Upvotes: 3

Related Questions