Мое приложение войдет в систему с помощью Google. Всякий раз, когда я запускаю приложение путем установки из моей android студии, оно работает, однако, когда я генерирую apk (не пакет приложений) для распространения и установки, ошибка возникает снова. Должен ли я использовать пакет приложений для устранения ошибки?
mAuth = FirebaseAuth.getInstance();
//Then we need a GoogleSignInOptions object
//And we need to build it as below
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(getString(R.string.default_web_client_id))
.requestEmail()
.build();
//Then we will get the GoogleSignInClient object from GoogleSignIn class
mGoogleSignInClient = GoogleSignIn.getClient(this, gso);
//Now we will attach a click listener to the sign_in_button
//and inside onClick() method we are calling the signIn() method that will open
//google sign in intent
findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signIn();
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//if the requestCode is the Google Sign In code that we defined at starting
if (requestCode == RC_SIGN_IN) {
//Getting the GoogleSignIn Task
Task <GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
try {
//Google Sign In was successful, authenticate with Firebase
GoogleSignInAccount account = task.getResult(ApiException.class);
//authenticating with firebase
firebaseAuthWithGoogle(account);
} catch (ApiException e) {
Toast.makeText(MainActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
}
private void firebaseAuthWithGoogle(GoogleSignInAccount acct) {
Log.e("Error", "firebaseAuthWithGoogle:" + acct.getId());
//getting the auth credential
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
//Now using firebase we are signing in the user here
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if (task.isSuccessful()) {
Log.e("Error", "signInWithCredential:success");
FirebaseUser user = mAuth.getCurrentUser();
startActivity(new Intent(MainActivity.this, main_activity2.class));
Toast.makeText(MainActivity.this, "User Signed In", Toast.LENGTH_SHORT).show();
} else {
// If sign in fails, display a message to the user.
Log.e("Error", "signInWithCredential:failure", task.getException());
Toast.makeText(MainActivity.this, "Authentication failed.",
Toast.LENGTH_SHORT).show();
}
// ...
}
});
}
//this method is called on click
private void signIn() {
//getting the google signin intent
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
//starting the activity for result
startActivityForResult(signInIntent, RC_SIGN_IN);
}
}
Я скопировал свой код SHA1 из Gradle (справа)> Задача> android> signatureReport. Я прочитал другие ответы не решили мою проблему. Я не разместил свое приложение в Play Store, просто тестирую его с друзьями!