16

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?

4
  • 1
    The JAR file you compiled with isn't the same version as the JAR file you executed with.
    – user207421
    Oct 12, 2015 at 5:38
  • thanks. I did a clean and rebuild still the same. Any suggestion on how to make sure the jar file get's updated? Oct 12, 2015 at 5:43
  • I didn't say anything about clean or rebuild. Neither of those will fix a versioning problem. I have the same suggestion as before. How you implement that is another question.
    – user207421
    Oct 12, 2015 at 5:48
  • 1
    But what is your suggestion? you have only said "The JAR file you compiled with isn't the same version as the JAR file you executed with"? I don't see a suggestion there I am compiling with Android Studio and running on the phone. It's not possible to replace the jar files on the phone. Oct 12, 2015 at 6:25

3 Answers 3

18

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.

8

This a bug in Play services library 8.1.0. Solved it by downgrading the play services library.

change

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

to

compile 'com.google.android.gms:play-services:7.8.+'

And the error no longer appears. My other code worked (as mentioned in the question because they were using the older version of the library) This will have to do until google releases an update.

Update: I wrote this before the other answer by galex came. That is the correct answer. But if you are unable to find the libraries that have these version conflicts, or if you can't change those library dependencies, the solution is to downgrade your play version to 7.8

2
  • 1
    compile 'com.google.android.gms:play-services:7.8.0' works. Always best practice to avoid using + if you can.
    – Ethan_AI
    Jan 15, 2016 at 0:44
  • Im going to use this myself, but we know this is not a good approach. We will stay forever in 7.8? Apr 29, 2016 at 17:12
-1
      compile 'com.google.android.gms:play-services:7.8.+'
compile 'com.google.android.gms:play-services-maps:7.8.+'

Solved for me after 10+ hours!!

2
  • It would be much better if you had any explanation on why you need to use an older version. May 25, 2016 at 20:08
  • My reasoning was that one of my libraries used 8.4, another used 7.8 therefore using the + would indicate to use whichever version was necessary at the moment of use.... May 31, 2016 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.