Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.io.IOException: AUTHENTICATION_FAILED in Android Firebase (and SERVICE_NOT_AVAILABLE)

I'm getting following error on some devices while fetching firebase token:

Fatal Exception: d.b.a.b.g.f
java.io.IOException: AUTHENTICATION_FAILED
com.google.android.gms.tasks.zzu.getResult (zzu.java:15)
MainActivity$3.onComplete (MainActivity.java:387)

Caused by java.io.IOException
    AUTHENTICATION_FAILED
    com.google.firebase.iid.zzu.then (zzu.java:16)
    com.google.android.gms.tasks.zzd.run (zzd.java:5)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
    com.google.android.gms.common.util.concurrent.zza.run (zza.java:6)
    java.lang.Thread.run (Thread.java:784)

Error log from Developer Console:

com.google.android.gms.tasks.RuntimeExecutionException: 
  at com.google.android.gms.tasks.zzu.getResult (zzu.java:15)
  at com.example.MainActivity$3.onComplete (MainActivity.java:387)
  at com.google.android.gms.tasks.zzj.run (zzj.java:4)
  at android.os.Handler.handleCallback (Handler.java:808)
  at android.os.Handler.dispatchMessage (Handler.java:101)
  at android.os.Looper.loop (Looper.java:166)
  at android.app.ActivityThread.main (ActivityThread.java:7529)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run (Zygote.java:245)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:921)
Caused by: java.io.IOException: 
  at com.google.firebase.iid.zzu.then (zzu.java:16)
  at com.google.android.gms.tasks.zzd.run (zzd.java:5)
  at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1162)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:636)
  at com.google.android.gms.common.util.concurrent.zza.run (zza.java:6)
  at java.lang.Thread.run (Thread.java:784)

Here is the code which is responsible to fetch firebase token:

FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task) {
                if (task.getResult() != null && task.isSuccessful()) {
                    String firebaseToken = task.getResult().getToken();
                }
            }
        });

I'm using following gradle dependencies.

implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.google.firebase:firebase-crashlytics:17.0.1'
implementation 'com.google.firebase:firebase-messaging:20.2.0'

I found similar questions and problems but no conclusive answer. Some suggest it may be result of broken internet connection but my app needs authenticate before entering the app so internet is available. Is there anybody encountered same issue? Best regards. enter image description here

like image 326
Aykut Uludağ Avatar asked Jun 24 '20 18:06

Aykut Uludağ


3 Answers

implementation platform('com.google.firebase:firebase-bom:26.4.0')
implementation "com.google.firebase:firebase-messaging"

The bomb has been planted (c) Google... And it is still there...
Ended up with the following code:

    try {
        FirebaseMessaging.getInstance().getToken().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                final String token = task.getResult();
                //GOT the token!
            }
        });
    } catch (Exception e) {
        // OMG, Firebase is used to log Firebase crash :)
        // I'm not sure if this will work...
        FirebaseCrashlytics.getInstance().recordException(e);
        gotFBCrash = true;
    }
    if (gotFBCrash) {
        FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(task -> {
            if (task.isSuccessful()) {
                final String token = task.getResult().getToken();
                //GOT the token!
            }
        });
    }

Actually the second part is two times deprecated code (thats why I'm here - updating to actual code results in app crash) but it works. You can use only the second way to obtain FCM token if you wish and hate try/catch

like image 128
Stan Avatar answered Oct 26 '22 14:10

Stan


It's bug on Firebase side, more and more users are affected by this issue:

Here the issue on Google issue tracker:

  • https://issuetracker.google.com/issues/143413382

And here the issue on Firebase issue tracker:

  • https://github.com/firebase/firebase-android-sdk/issues/1286

If you can get more information from your users to help Google developers fixing this issue, it could help =)

like image 4
Ghostwan Avatar answered Oct 26 '22 13:10

Ghostwan


in my case, non of above solved my issue, I get token from service callback and do with it whatever I need

public class LatestFirebaseMessagingService extends FirebaseMessagingService {

@Override
public void onNewToken(String mToken) {
    super.onNewToken(mToken);
    Log.e("TOKEN",mToken);
}
like image 1
itzhar Avatar answered Oct 26 '22 13:10

itzhar