24
votes

I'm getting following error with Firebase services.

 E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: FIS_AUTH_ERROR. Won't retry the operation.
 D/AndroidRuntime: Shutting down VM
    com.google.android.gms.tasks.RuntimeExecutionException: java.io.IOException: FIS_AUTH_ERROR
        at com.google.android.gms.tasks.zzu.getResult(Unknown Source:15)
        at com.myApp.MainActivity$2.onComplete(MainActivity.java:349)
        at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:237)
        at android.app.ActivityThread.main(ActivityThread.java:7804)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
     Caused by: java.io.IOException: FIS_AUTH_ERROR
        at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:82)
        at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:96)
        at com.google.firebase.iid.zzx.then(com.google.firebase:firebase-iid@@20.1.0:4)
        at com.google.android.gms.tasks.zzd.run(Unknown Source:5)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:919)

Here is the part of the code where crash occurs:

        FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
            @Override
            public void onComplete(@NonNull Task<InstanceIdResult> task) {
                if (task.getResult() != null && task.isSuccessful()) {
                    // Get new Instance ID token
                    firebaseToken = task.getResult().getToken();
                    prefs.edit().putString("firebaseToken", firebaseToken).apply();
                    registerToken();
                }
            }
        });

The error occurs in onComplete. Here is firebase dependencies which I use:

    // FIREBASE
implementation 'com.google.firebase:firebase-analytics:17.2.3'
implementation 'com.google.firebase:firebase-messaging:20.1.2'
implementation 'com.google.firebase:firebase-appindexing:19.1.0'
implementation 'com.google.firebase:firebase-ads:19.0.0'
implementation 'com.google.firebase:firebase-crashlytics:17.0.0-beta01'

I found this issue on Github related with my crash but there is no conclusive solution at all. Does anybody encountered this kind of issue? Thanks in advance.

Note: I don't use Flutter however the error occurs without flutter too. Device is Samsung A51 with Android 10.

Note 2: Firebase removed firebase-core. Problem can be related with that.enter image description here

18
If you have a bug report, please contact Firebase support with the details. support.google.com/firebase/contact/supportDoug Stevenson
I'm not sure it's the bug or my mistake. I don't think it's my mistake. I just updated firebase dependencies and application started to crash. Both debug and release versions. Thanks god I didn't release it. Normally, it worked perfectly before updating gradle.Aykut Uludağ
If you don't have code to show that reproduces the problem, then there's nothing we can do. Firebase support can at least collect your data and try to work toward a solution.Doug Stevenson
I added code already. I'm trying to get firebase token in my MainActivity and app crashes. Until I updated firebase dependencies, it worked perfectly. Crash occurs in onComplete part. I'm suspicious crash is related with firebase-core. Firebase removed it that's why I update dependencies.Aykut Uludağ
Okey I found a solution and posted it. There is some kind of bug in newer versions of firebase-messaging.Aykut Uludağ

18 Answers

20
votes

Temporary but working solution. Just downgrade com.google.firebase:firebase-messaging:20.1.2 to com.google.firebase:firebase-messaging:20.1.0. Apperantly, there is some kind of bug in 20.1.1 and 20.1.2 versions. App doesn't crash anymore.

UPDATE (11.04.2020): I tested in com.google.firebase:firebase-messaging:20.1.5 and apperantly problem has been fixed.


UPDATE (26.04.2020):

I found a permanent solution. First upgrade firebase dependencies to com.google.firebase:firebase-messaging:20.1.6. After that download google-services.json from firebase. Replace it with the current one. After that build > clean project otherwise you can get

API key expired. Please renew the API key

error. There is no problem with the key, it's some kind of bug of Google. If you completed these steps, add following code into onCreate of your top Application class which is you declared in manifest at the application tag.

FirebaseOptions options = new FirebaseOptions.Builder()
        .setApplicationId("APP ID") // Required for Analytics.
        .setProjectId("PROJECT ID") // Required for Firebase Installations.
        .setApiKey("GOOGLE API KEY") // Required for Auth.
        .build();
FirebaseApp.initializeApp(this, options, "FIREBASE APP NAME");

You can found your app id in the firebase > project settings. Also if you're debugging, don't forget to add the debug SHA-256 key to firebase.

Now I don't get crash anymore. Firebase services work perfectly.

16
votes

All you have to do is just make the API key you are using has permission to the following APIs:

  1. Firebase Installations API
  2. Firebase Cloud Messaging API
  3. FCM Registration API
  4. Cloud Messaging

You can change the restrictions from your google cloud -> APIs & Services -> Credentials

5
votes

The FIS_AUTH_ERROR means Authentication for Firebase installation sdk has failed. If you use a service that depends on Firebase installation sdk (or FIS), you need a valid authorization.

According to Firebase cloud messaging v20.1.1 release note:

Apps that use the Firebase auto-initialization process and the Gradle plugin to convert google-services.json into resources are unaffected. However, apps that create their own FirebaseOptions instances must provide a valid API key, Firebase project ID, and application ID.

So if you (or a service using fcm added by you) uses FirebaseOptions, it has to pass some additional values for the FIS.

Solutions

  • Downgrade to v20.1.0 of firebase-messaging (Not recommended though. It's like running from the problem)
  • Provide additional keys if you use FirebaseOptions
5
votes

All of a sudden the same error (FIS_AUTH_ERROR) appeared in one of my apps, where I use Firebase Cloud Messaging. Everything was working without any issues, and suddenly the app was not able to get the app/device token with getToken(). After hours of research I discovered something, which solved the problem for me. I decided to check the values in the file google-services.json to see if they match the corresponding parameters in the Firebase Console at the settings of my project. First I downloaded a brand new google-services.json, which I compared with the one I already had in my app's folder, and they both were simply the same without any difference. In the Firebase Console I was checking one by one the Project ID, the Project number, etc. When I got to the Web API Key its value looked quite similar to api_key from google-services.json, but still both values were different. Then I decided to edit the file, and in the place of api_key I've put the value from Web API Key. Then I've cleaned the project and rebuilt, and afterwards everything again started working just perfectly.

Add api key

4
votes

The correct fix is to add "Firebase Installations API" to the restrictions of your Google API Key (see google-services.json).

In your Google Cloud console, it's in APIs & Services, then Credentials. Open the API Key is look at "Restrictions".

No need to recompile.

4
votes

I found a solution to this problem

1) in Android Studio , in left panel "Project" swich Android view to Project view

2) copy file google-services.json NOT into "app" folder (like it says in instruction) ... but copy this file into the upper root folder

and it will work

3
votes

This is for sure, (if you finished all configuration) then version of firebase messaging is not compatible with other dependencies.

you can check dependencies here, my solution was to downgrade from implementation 'com.google.firebase:firebase-messaging:20.1.3' to implementation 'com.google.firebase:firebase-messaging:20.1.0'

3
votes

@mahdi-malv, @ambrose-bako, @steeve are right.


Firebase Android SDK updates on February 27 (M65) and afterwards introduced a new infrastructure service, the Firebase Installations SDK which comes with a dependency on the Firebase Installations API.
Firebase Installations requires valid Firebase options API key, project ID, and application ID (a.k.a. "appId") in order to successfully communicate with Firebase servers.

Errors during communication with the Firebase Installations API indicate invalid Firebase options or misconfigurations regarding API keys.

To mitigate the issue

  • make sure that your application is using valid Firebase options from the latest google-services.json file from your Firebase console: Firebase options: instructions and background.
  • If you use API restrictions, make sure that the API key used by your application is white-listed for the Firebase Installations API (and for your application): API restrictions: instructions and background
  • Regarding Application restrictions: Either set the radio button to None or make sure that your app is white-listed (with the correct SHA-1 certificate).

For details, please visit:
https://firebase.google.com/support/privacy/init-options

3
votes

In addition to Steeve's answer, the Firebase Messaging credentials should be restricted to these 3 Selected APIs:

Firebase Cloud Messaging API
Firebase Installations API
FCM Registration API

Go to the credentials on Google Cloud Console (APIs & Services -> Credentials), Click on the relevant key and select the 3 APIs above.

If you restrict usage to your Android apps, make sure to add SHA-1 fingerprints for your specific app. If you use internal app sharing, make sure to also add the SHA-1 of the internal app bundle as described here.

2
votes

Just in case, renamed the package name, deleted google-services.json, and going into firebase checked firebase-database (read\write).

Then deleted the old package and its hash from the firebase project settings, after adding a new package and hash, received a new google-services.json, after that everything worked

I think the error is that a package was specified in firebase but there was no hash

2
votes

If you have recently changed google-services.json file, you need to remove build file of your project and rebuild the project.

update: I got this error when I was testing my app in debug mode. In release version it was solved and worked correctly.

1
votes

Maybe a bit late, but hopefully this info may help someone out there.

I had the problem too with firebase-messaging:21.0.1. I followed all the instructions given in this thread, but nothing helped.

What was curious is that before the error E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: FIS_AUTH_ERROR. Won't retry the operation appeared the logcat showed Firebase Installations Service is unavailable.

After some investigation the solution was as follows. I used a self-signed certificate on my dev-server and trusted it in my app as described here: https://developer.android.com/training/articles/security-ssl.html#CommonProblems
Somehow this broke the whole SSL handshake stuff in android and I couldn't authenticate to the Firebase Installations Service anymore. After removing this and using plain http for my dev environment everything works again like a charm. (of course, for my prod server I'm using a ROOT trusted certificate, so no problems here)

0
votes

you need to add

apply plugin: 'com.google.gms.google-services'

implementation platform('com.google.firebase:firebase-bom:x.x.x')
implementation 'com.google.firebase:firebase-analytics'

to your app/build.gradle , these code will give to you when create google.services file on firebase console

0
votes

To remove this line:

FirebaseApp.initializeApp(getApplicationContext());

and let the SDK auto-initialize with the google-services.json solved it for me.

0
votes

Hope this helps someone:

In my situation, I used self-signed ca. So I need to use network-security-config.xml

After huge try and error, finally I add system directory in trust-anchors like below, FIS_AUTH_ERROR is gone and Firebase worked.

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <base-config>
        <trust-anchors>
            <certificates src="system" />  <!-- for Firebase -->
            <certificates src="user" /> <!-- for tooling.   Ex:Charles --> 
            <certificates src="@raw/ca_1"/> <!-- my self-signed ca-->
        </trust-anchors>
    </base-config>
</network-security-config>
0
votes

it's very-very confused, how I search a soltion for this error (with FIS_AUTH_ERROR), but with @Andreas Rayo Kniep's answer, especially with CURL command test, I know what's wrong with my problem.

CURL command to test firebase conf : curl -H "content-type: application/json" -d "{appId: 'YOUR-APP-ID', sdkVersion: 't:1'}" https://firebaseinstallations.googleapis.com/v1/projects/PROJECT-NAME/installations/?key=API-KEY;

I must change API key at google-services.json, because it's status : PERMISSION_DENIED, message : Requests from referer are blocked.

so I create new API key from google console, with restrict API for : Cloud Messaging, FCM Registration API, Firebase Cloud Messaging API, Firebase Installations API. and application restriction : None.

and problem was fixed!

I use : com.google.firebase:firebase-messaging:20.1.0 firebase_messaging: ^10.0.2

0
votes

In my case Crashlytics reports this only on a few Samsung devices, I think this is something with how Google services are implemented on certain Samsung devices so there is not much you can do.

0
votes

Best solution worked for me is upgrading dependencies and clean & re-build project