Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GoogleApiClient.connect()' was expected to be of type interface but was found to be virtual

Tags:

java

android

So I am connecting to the google api client like this.

        googleApiClient = new GoogleApiClient.Builder(context)
        .addApi(LocationServices.API)
        .addApi(ActivityRecognition.API)
        .addConnectionCallbacks(this)
        .addOnConnectionFailedListener(this)
        .build();
        googleApiClient.connect();

This exact same code I am using in several places and it works well. It's not different from what you see in their tutorials. But now:

java.lang.IncompatibleClassChangeError: The method 'void com.google.android.gms.common.api.GoogleApiClient.connect()' was expected to be of type interface but instead was found to be of type virtual (declaration of 'java.lang.reflect.ArtMethod' appears in /system/framework/core-libart.jar)

The line that the stacktrace reports is:

googleApiClient.connect();

Using play services 8.1

compile 'com.google.android.gms:play-services:8.1.0'

Has anyone this this?

like image 324
middlestump Avatar asked Oct 12 '15 05:10

middlestump


People also ask

How does googleapiclient connect to Google APIs?

Your GoogleApiClient instance will automatically connect after your activity calls onStart() and disconnect after calling onStop(). Your app can immediately begin making read requests to Google APIs after building GoogleApiClient, without waiting for the connection to complete.

How do I Disconnect a googleapiclient when it fails to connect?

If a required authenticated API fails to connect, the entire GoogleApiClient will fail to connect and a failed ConnectionResult will be delivered to OnConnectionFailedListener#onConnectionFailed. Once a connection has successfully completed the only way to disconnect the authenticated APIs is to call disconnect () on this GoogleApiClient.

What is the use of the Google API client builder?

The GoogleApiClient.Builderclass provides methods that allow you to specify the Google APIs you want to use and your desired OAuth 2.0 scopes. Here is a code example that creates a GoogleApiClientinstance that connects with the Google Drive service:

Why could not connect to Google Places API on Android?

Couldn't connect to Google API client: ConnectionResult {statusCode=API_UNAVAILABLE, resolution=null} because Google Places API for Android was not enabled in the API Console. @Elenasys : i am also getting same issue in production and build its works fine in development. Thanks in advance. I had a similar issue here.


1 Answers

The problem comes from one of the libraries your app depends on, library that depends itself on Google Play Services as well.

That library is using an older version of the Google Play Services SDK and it still relies on the fact that GoogleApiClient class is an interface. This has changed in 8.1.0 where it became an abstract class. This breaks backward compatibility because of the transitive dependencies of libraries.

Look if that library you use has a new updated version with 8.1.0 as well, or remove that dependency if possible.

More explanation can be found here.

like image 197
galex Avatar answered Oct 08 '22 02:10

galex