29

I have followed all the steps in firebase creation of project. When I run my application I get following error: E/FirebaseInstanceId: Failed to get FIS auth token java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException

I have added necessary libraries in build.gradle

But still it gives me error. Is there any solution for this.

Full stackstrace is as below:

-11 17:31:28.460 8093-8093/com.myapp V/FA: Registered activity lifecycle callback
03-11 17:31:28.510 8093-8153/com.myapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-11 17:31:28.550 8093-8156/com.myapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-11 17:31:28.550 8093-8093/com.myapp I/FirebaseInitProvider: FirebaseApp initialization successful
03-11 17:31:28.550 8093-8156/com.myapp I/System.out: (HTTPLog)-Static: isSBSettingEnabled false
03-11 17:31:28.570 8093-8158/com.myapp W/DynamiteModule: Local module descriptor class for com.google.firebase.auth not found.
03-11 17:31:28.590 8093-8158/com.myapp I/FirebaseAuth: [FirebaseAuth:] Preparing to create service connection to gms implementation
03-11 17:31:28.690 8093-8093/com.myapp W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter androidx.vectordrawable.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-11 17:31:28.700 8093-8093/com.myapp V/FA: onActivityCreated
03-11 17:31:28.720 8093-8139/com.myapp V/FA: App measurement collection enabled
03-11 17:31:28.720 8093-8139/com.myapp V/FA: App measurement enabled for app package, google app id: com.myapp, 1:694013098939:android:9c791b689fec2f9f78629e
03-11 17:31:28.720 8093-8139/com.myapp I/FA: App measurement initialized, version: 22048
03-11 17:31:28.720 8093-8139/com.myapp I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-11 17:31:28.720 8093-8139/com.myapp I/FA: To enable faster debug mode event logging run:
      adb shell setprop debug.firebase.analytics.app com.myapp
03-11 17:31:28.720 8093-8139/com.myapp D/FA: Debug-level message logging enabled
03-11 17:31:28.750 8093-8093/com.myapp I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
03-11 17:31:28.750 8093-8093/com.myapp I/art: Rejecting re-init on previously-failed class java.lang.Class<androidx.core.view.ViewCompat$2>
03-11 17:31:28.850 8093-8093/com.myapp D/TextView: setTypeface with style : 0
03-11 17:31:28.980 8093-8093/com.myapp D/TextView: setTypeface with style : 0
03-11 17:31:28.990 8093-8093/com.myapp I/Timeline: Timeline: Activity_launch_request id:com.myapp time:8027824
03-11 17:31:29.150 8093-8157/com.myapp E/FirebaseInstanceId: Failed to get FIS auth token
    java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException
        at com.google.android.gms.tasks.Tasks.zzb(Unknown Source)
        at com.google.android.gms.tasks.Tasks.await(Unknown Source)
        at com.google.firebase.iid.zzs.zzb(com.google.firebase:firebase-iid@@20.1.1:54)
        at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.1:89)
        at com.google.firebase.iid.zzv.run(com.google.firebase:firebase-iid@@20.1.1)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: com.google.firebase.installations.FirebaseInstallationsException
        at com.google.firebase.installations.FirebaseInstallations.doRegistrationInternal(com.google.firebase:firebase-installations@@16.0.0:333)
        at com.google.firebase.installations.FirebaseInstallations.doGetId(com.google.firebase:firebase-installations@@16.0.0:280)
        at com.google.firebase.installations.FirebaseInstallations.access$lambda$0(com.google.firebase:firebase-installations@@16.0.0)
        at com.google.firebase.installations.FirebaseInstallations$$Lambda$1.run(com.google.firebase:firebase-installations@@16.0.0)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
        at java.lang.Thread.run(Thread.java:818) 
Nensi Kasundra
  • 1,980
  • 6
  • 21
  • 34
Renuka
  • 783
  • 2
  • 9
  • 18

12 Answers12

13

Reset your phone time to the current time, if it's not. Resetting time worked for me.

shubham chouhan
  • 580
  • 7
  • 8
6

Update your google-services.json file. Delete the old one and re-download the new google-services.json from Firebase console > Project Settings.

sdgluck
  • 24,894
  • 8
  • 75
  • 90
3

Cloud Messaging version 20.1.1 changelog:

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.

google said: be aware of the following

Open Firebase console.
Accept if any new terms and conditions.
Check out package name miss-match.
If everything seems fine,
Add Firebase settings for you app once again.

urkoruche
  • 97
  • 1
  • 6
2

my first working App used com.google.firebase:firebase-messaging:20.2.0. and then i duplicate the project to make my second application. i registered new app in firebase console and replace the google-services.json. when i run i got the same error. i solved it by downgrading to version 20.1.5. after that i upgrade to the version 20.2.3 and the notification still working.

2

if your json ok, run clean project.

  • Thank you, I added new debug.keystore SHA-1 key to the firebase console, and updated google-services.json, but forgot to clean the project. Now it works. – Green Y. Jan 03 '22 at 17:29
2

Step 1 :- Update your code with FirebaseOption

FirebaseOptions options = new FirebaseOptions.Builder()
                .setApplicationId(FIREBASE_APPLICATION_ID)
                .setProjectId(FIREBASE_PROJECT_ID)
                .setGcmSenderId(FIREBASE_GCM_SENDER_ID)
                .setApiKey(FIREBASE_APIKEY_ID)
                .build();

        FirebaseApp.initializeApp( getApplicationContext(), options);

Step 2:-

/google play services/

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

implementation 'com.google.android.gms:play-services-auth:19.0.0'
// Firebase and ML Kit dependencies
implementation 'com.google.firebase:firebase-core:18.0.3'
implementation 'com.google.android.gms:play-services-vision:20.1.3'
implementation 'com.google.firebase:firebase-ml-vision-barcode-model:16.1.2'

// Import the BoM for the Firebase platform
implementation platform('com.google.firebase:firebase-bom:27.1.0')

// Declare the dependencies for the Crashlytics and Analytics libraries

// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-crashlytics'
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-ml-vision'

Step 3:-

 <service
        android:name="com.google.firebase.components.ComponentDiscoveryService"
        android:directBootAware="true"

        android:exported="false">
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.messaging.FirebaseMessagingRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.datatransport.TransportRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.iid.Registrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.installations.FirebaseInstallationsRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />
        <!--
            This registrar is not defined in the dynamic-module-support sdk itself to allow non-firebase
            clients to use it as well, by defining this registrar in their own core/common library.
        -->
        <meta-data
            android:name="com.google.firebase.components:com.google.firebase.dynamicloading.DynamicLoadingRegistrar"
            android:value="com.google.firebase.components.ComponentRegistrar" />

    </service>

    <provider
        android:name="com.google.firebase.provider.FirebaseInitProvider"
        android:authorities="Your_package_name.firebaseinitprovider"
        android:directBootAware="true"
        android:exported="false"
        android:initOrder="100" />
   <receiver
        android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />

            <category android:name="Your_package_name" />
        </intent-filter>
    </receiver>

Step:- 4 include the permission

All you have to do is just make the API key you are using has permission to the following APIs:
Firebase Installations API
Firebase Cloud Messaging API
Cloud Messaging
FCM Registration API

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

This is the complete working solution which i have tasted and used in my code

Imran khan
  • 123
  • 1
  • 12
1

Make sure you have added your debug and release keystone SHA1 in Google Cloud Platform > API Android Keys

Sandeep Singh
  • 241
  • 1
  • 9
1

Sometimes switching to a different version of google-services will resolve this error.

I was getting "E/FirebaseMessaging: Failed to get FIS auth token" on some emulator devices and not on others. Didn't figure out exactly what difference caused the error, but it tended to be more common on newer APIs (30, 31,..).

Issue was resolved by switching from

classpath 'com.google.gms:google-services:4.3.15'

to

classpath 'com.google.gms:google-services:4.3.13'

jk7
  • 1,958
  • 1
  • 22
  • 31
1

In my case it was "just" that the Emulator had no Internet conection. I'm on a Mac M1. How to solve? Was easy thanks to this guy https://medium.com/@daydreamer_/how-to-fix-android-emulator-wi-fi-connected-with-no-internet-c62fd4ed652d :

Android Emulator requires the Google DNS 8.8.8.8 and 4.4.4.4. Set it on your computer as DNS and off you go.

e1000
  • 39
  • 3
0

Check if your emulator is connected to wi-fi

0

In my case there was another problem - firebase were initialized too early and throws error like you mentioned.

Before:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  final fcmToken = await FirebaseMessaging.instance.getToken();

  // got error - Failed to get FIS auth token
  runApp(const MyApp());
}

The trick is to launch Firebase initialization AFTER runApp():

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  runApp(const MyApp());

  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );

  // works fine!
  final fcmToken = await FirebaseMessaging.instance.getToken();
}

Hope this will help.

Alexander Guskov
  • 371
  • 1
  • 2
  • 14
-3

It seems the issue of firebase SDK (com.google.firebase:firebase-analytics:17.2.3). I still got the same log

Fatal Exception: java.lang.IllegalStateException
com.google.firebase.iid.FirebaseInstanceId.zzl (com.google.firebase:firebase-iid@@20.1.1:75)
com.google.firebase.iid.FirebaseInstanceId.getId (com.google.firebase:firebase-iid@@20.1.1:49)
com.google.firebase.perf.internal.zzf.zzbu (com.google.firebase:firebase-perf@@19.0.5:181)
com.google.firebase.perf.internal.zzf.zzbt (com.google.firebase:firebase-perf@@19.0.5:44)
Nathan
  • 1