18

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

Aykut Uludağ
  • 1,876
  • 5
  • 18
  • 34

5 Answers5

6
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

Stan
  • 6,511
  • 8
  • 55
  • 87
4

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

Here the issue on Google issue tracker:

And here the issue on Firebase issue tracker:

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

Ghostwan
  • 263
  • 1
  • 4
  • 11
1

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);
}
itzhar
  • 12,743
  • 6
  • 56
  • 63
1

It's been two years since the question's been posted, BUT the exception still exists on some devices / emulators. One of the reasons is unavailable/disabled Google Play app/services (I've just encountered this exception today).

Google Play services is required to create a token and it will fail on devices without it.

Matt
  • 665
  • 6
  • 16
0

Try Sign in into google account in android studio using top right sign in icon. This works for me.