我正在尝试在我的Android应用中检索已登录用户的联系电子邮件的列表。从此处的教程开始,以下行:
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
导致Android Studio错误“ GoogleSignIn被标记为内部,不应从应用程序访问”。
该项目可以编译,但是当我尝试登录时,logcat
输出:
W/GooglePlayServicesUtil: Google Play services out of date. Requires 12210000 but found 11947470
我的app/gradle.build
包含:
dependencies {
...
implementation 'com.google.android.gms:play-services-auth:12.0.0'
implementation 'com.google.firebase:firebase-core:12.0.0'
implementation 'com.google.firebase:firebase-firestore:12.0.0'
}
apply plugin: 'com.google.gms.google-services'
当我注释掉Firebase时:
dependencies {
...
implementation 'com.google.android.gms:play-services-auth:12.0.0'
//implementation 'com.google.firebase:firebase-core:12.0.0'
//implementation 'com.google.firebase:firebase-firestore:12.0.0'
}
//apply plugin: 'com.google.gms.google-services'
我没有收到错误并成功登录。
我想将Firestorm集成到我的应用程序中,是否需要重新设计登录过程?如果是这样,怎么办?
要复制,这是我的MainActivity
。编译Firebase后,Log.w
调用输出signInResult:failed code=12500
:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
static final int RC_SIGN_IN = 1000;
GoogleSignInClient mGoogleSignInClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
findViewById(R.id.google_sign_in_button).setOnClickListener(this);
}
@Override
public void onClick(View v) {
startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);
}
}
private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
try {
GoogleSignInAccount account = completedTask.getResult(ApiException.class);
} catch (ApiException e) {
Log.w("signInResult:failed code=" + e.getStatusCode());
}
}
}
和我的布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.XXX.MainActivity">
<com.google.android.gms.common.SignInButton
android:id="@+id/google_sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
https://developers.google.com/android/guides/releases
版本12.0.0的已知问题
...
- 注释会导致虚假的皮棉错误,声称GoogleSignIn和CredentialsClient仅限内部使用。这些可以安全地忽略。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句