android - “com.google.android.gms.common.api.GoogleApiClient”已弃用

标签 android firebase firebase-authentication google-authentication

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

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

我开始收到有关已弃用类的警告。

Warning:(26, 12) 'com.google.android.gms.common.api.GoogleApiClient' is deprecated

还有

Warning:(27, 36) 'com.google.android.gms.common.api.GoogleApiClient.Builder' is deprecated

这是我的代码:

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

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

最佳答案

是的,GoogleApiClient 已被弃用。

根据 documentation :

When you want to make a call to one of the Google APIs provided in the Google Play services library (such as Google Sign-in and Drive), you need to create an instance of one the API client objects, which are subclasses of GoogleApi

特别是对于身份验证 API,您现在需要使用 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);

您可以引用以下文档了解更多详细信息:

关于android - “com.google.android.gms.common.api.GoogleApiClient”已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57575770/

相关文章:

android - 从字典、内容提供者、Android 中获取单词

android - 系统操作/Intent 是否以特定权限级别发送?

swift - 覆盖变量中的值

javascript - 无法编辑由其他用户在 Firestore 中创建的文档 (Vue.js/Firestore)

带有 WebView 的 Flutter 应用程序中的 Firebase 身份验证

android - 未授予通话和短信权限,但仍收到来自 Google Play 的警告

安卓图像尺寸

firebase - Firebase Auth 导入是否保留给定的 UID?

java - 发出外部 HTTPS 请求时 AWS Lambda 超时

javascript - Firebase Google signInWithRedirect 在身份验证成功后不会重定向到指定页面