So for some reason, my app works with google sign in on some days and it doesn't on other days. Lately, I've been battling with
java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken(). Now the last time it happened I had to delete my project and google cloud API's to then be able to connect without a token error. I'm at my wit's end would be nice to know a definite fix since I don't want to launch a prototype with this problem still persisting. Attached is my login code and my error log.
/**
* This method will return the results after the intent has started
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(TAG, "onActivityResult: "+ Auth.GoogleSignInApi.getSignInResultFromIntent(data).getSignInAccount());
switch (requestCode) {
case REQUEST_CODE_SIGN_IN:
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount account = result.getSignInAccount();
firebaseAuthWithGoogle(account);
break;
default:
super.onActivityResult(requestCode, resultCode, data);
break;
}
}
/**
* Kick of google authentication through firebase
* */
private void firebaseAuthWithGoogle(GoogleSignInAccount acct){
//show progressbar
showProgressDialog();
AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signWithCredential:onComplete:" + task.isSuccessful() + FirebaseAuth.getInstance().getCurrentUser());
handleSignInSuccess();
hideProgressDialog();
}
});
}
Error log:
D/FA: Logging event (FE): _e, Bundle[{_o=auto, _et=13259}]
V/FA: Inactivity, disconnecting from the service
D/LoginActivity: onActivityResult: null
D/AndroidRuntime: Shutting down VM
E/UncaughtException: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1006, result=0, data=Intent { (has extras) }} to activity {com.example.oseix.umc/com.example.oseix.umc.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()' on a null object reference
at com.example.oseix.umc.LoginActivity.firebaseAuthWithGoogle(LoginActivity.java:286)
at com.example.oseix.umc.LoginActivity.onActivityResult(LoginActivity.java:269)
at android.app.Activity.dispatchActivityResult(Activity.java:6917)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
D/FA: Logging event (FE): _ae, Bundle[{_o=crash, timestamp=1476203958303, fatal=1}]
V/FA: Using measurement service
V/FA: Connecting to remote service
D/FirebaseCrashApiImpl: throwable java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1006, result=0, data=Intent { (has extras) }} to activity {com.example.oseix.umc/com.example.oseix.umc.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()' on a null object reference
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.oseix.umc, PID: 5920
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1006, result=0, data=Intent { (has extras) }} to activity {com.example.oseix.umc/com.example.oseix.umc.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.android.gms.auth.api.signin.GoogleSignInAccount.getIdToken()' on a null object reference
at com.example.oseix.umc.LoginActivity.firebaseAuthWithGoogle(LoginActivity.java:286)
at com.example.oseix.umc.LoginActivity.onActivityResult(LoginActivity.java:269)
at android.app.Activity.dispatchActivityResult(Activity.java:6917)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.