我成功使用旧版本的firebase auth ui,但在升级到最新版本后,我在尝试使用Google登录时收到以下错误:
E/AuthUI: A sign-in error occurred.
com.firebase.ui.auth.FirebaseUiException: Code: 10, message: 10:
at com.firebase.ui.auth.data.remote.GoogleSignInHandler.onActivityResult(GoogleSignInHandler.java:106)
at com.firebase.ui.auth.ui.idp.AuthMethodPickerActivity.onActivityResult(AuthMethodPickerActivity.java:225)
at android.app.Activity.dispatchActivityResult(Activity.java:7235)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4320)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4367)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1649)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Facebook和电子邮件登录都很好。
我在我的app gradle中使用这些依赖项:
implementation 'com.google.android.gms:play-services-auth:15.0.1'
implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.facebook.android:facebook-login:4.32.0'
implementation 'com.google.firebase:firebase-config:16.0.0'
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
以下在我的项目级别gradle:
classpath 'com.google.gms:google-services:4.0.1'
登录活动:
public class ActivityLoginView extends ActivityBase {
// Misc
public static final int RC_SIGN_IN = 100;
public static final String TAG = "ActivityLoginView";
public ActivityLoginViewModel activityLoginViewModel;
private static final String PRIVACY_POLICY_URL = "https://www.editedout.com/pages/privacy";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
activityLoginViewModel = new ActivityLoginViewModel(this);
if (!activityLoginViewModel.isGooglePlayServicesAvailable()) {
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("No Google Play Services");
alertDialog.setMessage("This app requires Google Play Services to be installed and enabled");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
System.exit(0);
}
});
alertDialog.show();
} else {
FirebaseUser currentUser = FirebaseAuth.getInstance().getCurrentUser();
// See if user is logged in already
if (currentUser != null) {
// User already signed in
if (!BuildConfig.DEBUG) {
Crashlytics.setUserIdentifier(currentUser.getUid());
Crashlytics.setUserName(currentUser.getDisplayName());
Crashlytics.setUserEmail(currentUser.getEmail());
}
activityLoginViewModel.saveUserToFirebase();
} else {
startActivityForResult(
AuthUI.getInstance().createSignInIntentBuilder()
.setTheme(R.style.LoginTheme)
.setLogo(R.drawable.loginlogo)
.setAvailableProviders(getSelectedProviders())
.setPrivacyPolicyUrl(PRIVACY_POLICY_URL)
.setIsSmartLockEnabled(!BuildConfig.DEBUG)
.build(),
RC_SIGN_IN);
}
}
}
public void startMain() {
if (SPManager.getBoolean(this, SPManager.kOnBoardShown)) {
Intent intent = new Intent(this, ActivityHomePage.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
} else {
startActivity(ActivityOnBoard.newIntent(this));
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RC_SIGN_IN) {
handleSignInResponse(resultCode, data);
}
}
private void handleSignInResponse(int resultCode, Intent data) {
IdpResponse response = IdpResponse.fromResultIntent(data);
// Successfully signed in
if (resultCode == RESULT_OK) {
activityLoginViewModel.saveUserToFirebase();
} else {
// Sign in failed
if (response == null) {
// User pressed back button
showSnackbar(R.string.sign_in_cancelled);
return;
}
if (response.getError().getErrorCode() == ErrorCodes.NO_NETWORK) {
showSnackbar(R.string.no_internet_connection);
return;
}
showSnackbar(R.string.unknown_error);
Log.e(TAG, "Sign-in error: ", response.getError());
}
}
private List<AuthUI.IdpConfig> getSelectedProviders() {
List<AuthUI.IdpConfig> selectedProviders = new ArrayList<>();
selectedProviders.add(new AuthUI.IdpConfig.GoogleBuilder()
.build());
selectedProviders.add(new AuthUI.IdpConfig.FacebookBuilder()
.build());
selectedProviders.add(new AuthUI.IdpConfig.EmailBuilder()
.setRequireName(true)
.setAllowNewAccounts(true)
.build());
//selectedProviders
// .add(new AuthUI.IdpConfig.PhoneBuilder().build());
return selectedProviders;
}
public void showSnackbar(@StringRes int errorMessageRes) {
View parentLayout = findViewById(android.R.id.content);
Snackbar.make(parentLayout, errorMessageRes, Snackbar.LENGTH_LONG).show();
}
@Override
public void onBackPressed() {
finishAffinity();
}
答案 0 :(得分:16)
修正了它。我忘了将新的调试SHA1添加到Firebase。
答案 1 :(得分:1)
要解决此问题,您应该在build.gradle
文件中添加以下实现:
implementation 'com.firebaseui:firebase-ui-database:4.0.0'
仅使用implementation 'com.firebaseui:firebase-ui-auth:4.0.0'
是不够的,您需要同时使用它们。
也不要忘记将调试SHA1指纹添加到Firebase控制台。
答案 2 :(得分:0)
就我而言,是因为我删除了调试buildType的密钥库。
据我所知SHA-1是根据您的密钥库生成的,并且如果您未为调试版本指定密钥库,则Android Studio会自动使用生成的密钥库,当然其中的SHA-1也不同
只需重新包含为我工作的密钥库即可。
答案 3 :(得分:0)
Step1)从您的android studio生成SH1
单击Gradle-> signingReport->在“运行”控制台中,您将能够看到SH1值
第2步)将SH1添加到Firebase控制台。 (https://console.firebase.google.com)
转到->您的项目名称->设置->常规->添加指纹
添加我们在步骤1中生成的SH1并保存
答案 4 :(得分:0)