Monday 5 July 2021

GoogleSignIn.getLastSignedInAccount() returns null on release build

I'm trying to add google sign-in to my android app. Everything works fine on debug build. But when I push the apk for internal testing on Google Play it throws Google SignIn API Exception 10. Should I add anything extra to my console?

So far I've done the following things, 1, Created new firebase project 2, Added SHA-1 to firebase console. 3, Downloaded google-services.json from firebase and copied to app folder. 4, On my https://console.cloud.google.com/apis/credentials page everything is automatically filled by firebase. So, I didn’t do anything there. 5, Add all required libraries to android project

     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.activity_login);
            SignInButton signInButton = findViewById(R.id.sign_in_button);
            signInButton.setSize(SignInButton.SIZE_WIDE);
    
            GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestIdToken(getString(R.string.default_web_client_id))
                    .requestEmail()
                    .build();
    mGoogleSignInClient = GoogleSignIn.getClient(this, so);
    }

 @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
        if (requestCode == RC_SIGN_IN) {
            // The Task returned from this call is always completed, no need to attach
            // a listener.
            // Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            try {
                // Google Sign In was successful, authenticate with Firebase
                GoogleSignInAccount account = task.getResult(ApiException.class);
                Log.e(TAG, "firebaseAuthWithGoogle:" + account.getId());
                //firebaseAuthWithGoogle(account.getIdToken());
            } catch (ApiException e) {
                // Google Sign In failed, update UI appropriately
                Log.e(TAG, "Google sign in failed", e);
            }
            handleSignInResult(task);
        }
    }

   private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
         String personName = "", personEmail = "", aid = "";
            Uri personPhoto = Uri.parse("");
            // GoogleSignInAccount acct = GoogleSignIn.getLastSignedInAccount(this);
            GoogleSignInAccount acct = completedTask.getResult();
            if (acct != null) {
                personName = acct.getDisplayName();
                personEmail = acct.getEmail();
                personPhoto = acct.getPhotoUrl();
                aid = acct.getId();
                Log.e("ID_TOKEN", acct.getIdToken() + "");
            } 
}


from GoogleSignIn.getLastSignedInAccount() returns null on release build

No comments:

Post a Comment