I create an application using the Firebase service, with the authorization function using a Google account. There is such a LoginActivity code:

public class LoginActivity extends AppCompatActivity implements ChooseGroupFragment.InterfaceCommunicator, GoogleApiClient.OnConnectionFailedListener, View.OnClickListener { private Button go_button, choose_group; private static final int RC_SIGN_IN = 9001; private SharedPreferences mSharedPreferences; private SignInButton mSignInButton; private FirebaseAuth mFirebaseAuth; private boolean CHECK = false; private GoogleApiClient mGoogleApiClient; public static final String APP_PREFERENCES = "user_settings"; public static final String APP_PREFERENCES_GROUP = "Group"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login_layout); mSharedPreferences = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE); go_button = (Button)findViewById(R.id.go); mSignInButton = (SignInButton)findViewById(R.id.add_account_button); choose_group = (Button)findViewById(R.id.group_button); go_button.setOnClickListener(this); mSignInButton.setOnClickListener(this); choose_group.setOnClickListener(this); mFirebaseAuth = FirebaseAuth.getInstance(); GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) .requestIdToken("XXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com") // идентификатор ключа OAuth 2.0 для Web Client .requestEmail() .build(); mGoogleApiClient = new GoogleApiClient.Builder(this) .enableAutoManage(this,this) .addApi(Auth.GOOGLE_SIGN_IN_API, gso) .build(); } @Override public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { Toast.makeText(this, "Google Play Services error.", Toast.LENGTH_SHORT).show(); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.go: SharedPreferences.Editor editor = mSharedPreferences.edit(); if(!choose_group.getText().equals("Выбрать группу") && CHECK){ editor.putString(APP_PREFERENCES_GROUP, choose_group.getText().toString()); editor.apply(); Intent intent = new Intent(LoginActivity.this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); }else { Toast.makeText(getApplicationContext(), "Добавьте Google-аккаунт и выберите вашу группу.", Toast.LENGTH_LONG).show(); } break; case R.id.group_button: if (CHECK){ FragmentManager manager = getSupportFragmentManager(); ChooseGroupFragment fragment = new ChooseGroupFragment(); fragment.show(manager, "dialog"); }else{ Toast.makeText(this, "Сначала добавьте свой Google-аккаунт", Toast.LENGTH_LONG).show(); } break; case R.id.add_account_button: Authorize(); break; } } private void Authorize(){ Intent athorizeIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); startActivityForResult(athorizeIntent, RC_SIGN_IN); } @Override public void TextDialog(String text) { choose_group.setText(text); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if(requestCode == RC_SIGN_IN){ GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); if(result.isSuccess()){ GoogleSignInAccount account = result.getSignInAccount(); firebaseAuthWithGoogle(account); }else{ // выполняется этот код, появляется сообщение ниже Toast.makeText(LoginActivity.this, "Google-SignIn failed.", Toast.LENGTH_SHORT).show(); } } } private void firebaseAuthWithGoogle(GoogleSignInAccount acct){ AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); mFirebaseAuth.signInWithCredential(credential) .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() { @Override public void onComplete(@NonNull Task<AuthResult> task) { /*If sign in fails, display a message to the user. If sign in succeeds the auth state listener will be notified and logic to handle the signed in user can be handled in the listener.*/ if (!task.isSuccessful()){ Toast.makeText(LoginActivity.this, "Authentication failed.", Toast.LENGTH_SHORT).show(); } Toast.makeText(LoginActivity.this, "Аккаунт добавлен.", Toast.LENGTH_SHORT).show(); CHECK = true; } }); } } 

I run the application in debug mode. When you click on the add account button, a small selection window appears, when you select an account, the window closes, an error occurs in the onActivityResult () method, result.isSuccess () returns FALSE (indicated in my code). In the log nothing related to this, I can not find. I added google-services.json, the imprint of the release key SHA-1 is in place. I can not understand, then I could miss ...

  • You, probably, launch not release version of application? Those. Do not sign this release key? Most likely, all you have to do is add the SHA-1 debazh key in the console and update google-services.json in the project - Yuriy SPb
  • @YuriSPb yes, you are right. Now it all worked. I constantly stumble over these debug / release keys: D - YungBlade

1 answer 1

Probably you run a non-release version of the application. Those. Do not sign it with a release key. Most likely you just need to add SHA-1 debazhnyh key in the console and update google-services.json in the project