我在我的应用程序中使用 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/