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

6

19

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

Dyann answered 24/6, 2020 at 18:58 Comment(5)
I experienced this issue, so factory reset the device and it works now. Sadly I do not know what caused it.Cockswain
How will you factory reset a user's device? @HungryArthur. What if your app users are getting this error?Itagaki
I should have pointed out these were on internal devices that we had control over.Cockswain
If this happens on Android Emulator, do a Wipe Data from AVD on that specific instance and then start it.Aperient
@ŠemsudinTafilović - this worked haven't tested on real device thanks.Topo
C
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

Choline answered 2/4, 2021 at 14:29 Comment(0)
S
5

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 =)

Shearwater answered 27/8, 2020 at 12:25 Comment(0)
A
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);
}
Aspersion answered 5/9, 2021 at 21:6 Comment(0)
F
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.

Fredericafrederich answered 19/8, 2022 at 9:27 Comment(1)
In production users probably downloaded the app via Google Play, so play services are enabledAsur
R
1

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

Reckoner answered 25/4, 2023 at 8:55 Comment(1)
This what worked for me, Thank youUnderproduction
K
0

One of the reasons might be that multiple emulators are running. Leaving only one emulator solved the issue for me.

Knox answered 20/6, 2024 at 15:9 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.