首先,我已经尝试过这个解决方案:Patrik's Solution。没起作用!
如果我直接从Android运行,它可以很好地工作,但是当我创建和安装签名的APK时,就会发生异常。会发生什么事?
我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
...
btnGoogleLogin.setOnClickListener(V -> singinGoogle());
...
}
void singinGoogle(){
Intent singinIntent = mGoogleSignInClient.getSignInIntent();
startActivityForResult(singinIntent,GOOGLE_SIGN);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==GOOGLE_SIGN){
Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try{
GoogleSignInAccount account = task.getResult(ApiException.class);
if(account!=null) {
firebaseAuthWithGoogle(account);
}
}catch (ApiException e){
Toast.makeText(this, "ERROR: "+e.getMessage(), Toast.LENGTH_LONG).show();
DialogError de = new DialogError();
FragmentManager fm = this.getSupportFragmentManager();
dec.show(fm, "");
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount account){
AuthCredential credential = GoogleAuthProvider.getCredential(account.getIdToken(),null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this,task -> {
if(task.isSuccessful()){
FirebaseUser user = mAuth.getCurrentUser();
}else {
Toast.makeText(this, "The Login as Failed", Toast.LENGTH_SHORT).show();
}
});
} 发布于 2020-02-06 16:02:09
我发现了这个问题,当我生成签名的应用程序时,play商店为应用程序生成一个新的SHA1和MD5密钥。因此,问题的解决方案只是将Play Store密钥复制到Firebase。
逐步解决方案:
注意:您也可以保留Android生成的键,这样应用程序就可以在调试和Google上运行。
希望这能有所帮助!
https://stackoverflow.com/questions/60085462
复制相似问题