GoogleApiClient.connect()'预计是类型的接口,但被认为是虚拟接口、类型、GoogleApiClient、connect

2023-09-05 06:00:37 作者:以为姐姐是我的唯一

于是我连接到谷歌API客户端这样的。

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();

这完全一样的code,我用在几个地方,它工作得很好。这不是从你自己的教程看到不同。但现在:

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:方法'无效   com.google.android.gms.common.api.GoogleApiClient.connect()是   预计类型的接口,而是被认为是类型   对java.lang.reflect.ArtMethod虚拟(声明出现在   /system/framework/core-libart.jar)

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();

使用播放服务8.1

Using play services 8.1

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

有没有人这样呢?

Has anyone this this?

推荐答案

这个问题是从一个你的应用程序依赖于库,库取决于自身对谷歌播放服务也是如此。

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

这是库使用谷歌播放服务SDK的旧版本,它仍然依赖于一个事实,即GoogleApiClient类是一个接口。 这在8.1.0改变它变成一个抽象类。这打破因为图书馆的传递依赖的向后兼容性。

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.

看,如果你使用该库有一个新的更新版本8.1.0为好,或者如果可能的话删除相关性。

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

More说明可以在这里找到