不推荐使用"com.google.android.gms.common.api.GoogleApiClient" [英] 'com.google.android.gms.common.api.GoogleApiClient' is deprecated
问题描述
我在我的应用程序中使用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'已弃用
Warning:(26, 12) 'com.google.android.gms.common.api.GoogleApiClient' is deprecated
还有
警告:(27,36)'com.google.android.gms.common.api.GoogleApiClient.Builder'已弃用
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();
}
我的应用程序仍在运行,但是如何在不需要降级版本的情况下摆脱此警告?
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的子类
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
.
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:
- Integrating Google Sign-In into Your Android App
- Moving Past GoogleApiClient
这篇关于不推荐使用"com.google.android.gms.common.api.GoogleApiClient"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!