本文介绍了'com.google.android.gms.common.api.GoogleApiClient' 已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用中使用了 Google 登录方法,并且我今天已将依赖项更新为:

I'm using in my app Google sign-in method and I have updated today my dependencies to:

implementation "com.google.firebase:firebase-core:17.1.0"
implementation "com.google.firebase:firebase-auth:19.0.0"

我盯着收到关于已弃用类的警告.

And I stared to get warnings about deprecated classes.

警告:(26, 12) 'com.google.android.gms.common.api.GoogleApiClient' 已弃用

警告:(27, 36) 'com.google.android.gms.common.api.GoogleApiClient.Builder' 已弃用

这是我的代码:

static GoogleApiClient provideGoogleApiClient(Application app) { //deprecated
    return new GoogleApiClient.Builder(app) //deprecated
            .addApi(Auth.GOOGLE_SIGN_IN_API).build();
}

我的应用程序仍在运行,但如何在无需降级版本的情况下摆脱此警告?

My app is still working but how can I get rid of this warnings without the need to downgrade the versions?

推荐答案

是的,GoogleApiClient 已被弃用.

Yeah GoogleApiClient has been deprecated.

根据文档:

当您想要调用在Google Play 服务库(例如 Google 登录和云端硬盘),您需要创建一个 API 客户端对象的实例,它们是GoogleApi 的子类

特别是对于身份验证 api,您现在需要使用 GoogleSignInClient.

Particularly for the authentication api, you now need to use GoogleSignInClient.

    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();

    // Build a GoogleSignInClient with the options specified by gso.
    mGoogleSignInClient = GoogleSignIn.getClient(this, gso);

您可以参考以下文档了解更多详情:

You may refer following documentations for more details:

这篇关于'com.google.android.gms.common.api.GoogleApiClient' 已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 11:54