Search code examples
androidandroid-layoutgoogle-plusgoogle-plus-signin

Google Plus Login - Release version doesn't works (ask the user, but not log in)


I've a problem: the Google Plus API ask to choose the user, but after this, the dialog dismiss and nothing happeness. I changed the SHA1 four times, I made the keystore two times and nothing. It happens, after that I generate the release version of apk. Follow my code of my LoginActivity:

Version of Google Play Services: 11.8.0

LoginActivity.java

public class LoginActivity extends BaseActivity {
    //    FACEBOOK AND PLUS
    private static final int RC_SIGN_IN = 1;
    private CallbackManager callbackManager;
    private GoogleSignInClient mGoogleSignInClient;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);

        //  login and register, by Google Plus
        mGoogleSignInClient = presenter.googlePlusGetInstance(mGoogleSignInClient, this);
    }


    @OnClick(R.id.btn_login_googleplus)
    void loginGooglePlus() {
        try {
            startActivityForResult(mGoogleSignInClient.getSignInIntent(), RC_SIGN_IN);
        } catch (Exception e) {
            FastUtils.snackbarSlow(llPrincipal, String.valueOf(e));
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        callbackManager.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_CANCELED) {
            if (requestCode == RC_SIGN_IN) {
                Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
                handleSignInResult(task);

                FastUtils.openClass(this, WelcomeActivity.class);
                startActivity(intent);
            }
        }
    }

    private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
        try {
            GoogleSignInAccount account = completedTask.getResult(ApiException.class);
            // Signed in successfully, show authenticated UI.
            Log.i("LOG", "[ GOOGLE+ ] - Its alright");
            if (account != null) {
                foto = account.getPhotoUrl();

                Log.i("LOG", "handleSignInResult: Name -> " + account.getDisplayName());
                Log.i("LOG", "handleSignInResult: E-mail -> " + account.getEmail());
            } else {
                Log.i("LOG", "[ GOOGLE+ ] - ELSE");
            }
        } catch (ApiException e) {
            Log.i("LOG", "[ GOOGLE+ ] - ERRO: " + e.getLocalizedMessage());
        }
    }
}

Solution

  • First Posibility

    The SHA of Signed APK is changed. You need to get SHA of Signed APK and put them in Google Console. Most Possible case.

    You can get it from below steps

    Traverse to the "bin" folder of the jdk path present in Java.

    Open terminal and enter:

    keytool -list -v -keystore "key store path" -alias "key alias"
    

    Enter your key password and this will print out your release SHA1.

    Second Possibility

    If you have turned on the new App Signing from Google Play Console than you will find SHA over there only. This will be the only case if you have uploaded app on store.