Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FirebaseInstallationsException on latest version

Every time I update my app's Firebase dependencies to anything more recent than the Feb. 27 2020 update, I start seeing this exception when I run my app:

04-29 18:21:58.170  3314  3541 E Firebase-Installations: Firebase Installations can not communicate with Firebase server APIs due to invalid configuration. Please update your Firebase initialization process and set valid Firebase options (API key, Project ID, Application ID) when initializing Firebase.
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId: Failed to get FIS auth token
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId: java.util.concurrent.ExecutionException: com.google.firebase.installations.FirebaseInstallationsException
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.android.gms.tasks.Tasks.await(Unknown Source:23)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.firebase.iid.zzt.zzb(com.google.firebase:firebase-iid@@20.1.6:54)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.firebase.iid.zzt.zza(com.google.firebase:firebase-iid@@20.1.6:72)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.firebase.iid.zzs.run(Unknown Source:12)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.android.gms.common.util.concurrent.zza.run(com.google.android.gms:play-services-basement@@17.1.1:6)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at java.lang.Thread.run(Thread.java:764)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId: Caused by: com.google.firebase.installations.FirebaseInstallationsException
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.firebase.installations.FirebaseInstallations.doNetworkCall(com.google.firebase:firebase-installations@@16.2.2:350)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.firebase.installations.FirebaseInstallations.lambda$doRegistrationInternal$0(com.google.firebase:firebase-installations@@16.2.2:323)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at com.google.firebase.installations.FirebaseInstallations$$Lambda$5.run(Unknown Source:4)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
04-29 18:21:58.177  3314  3543 E FirebaseInstanceId:    ... 1 more

I've read several related questions and tried all of the following:

  1. I verified my API key has no restrictions (SHA-1 or API restrictions) in Google Cloud Platform.
  2. I verified the google-services.json provided by Firebase matches the one included in my project.
  3. I verified the API key, project ID, and application ID in the google-services.json file are correct.
  4. I verified all the devices I'm testing on (a mix of emulators with different API versions and physical devices) have the Play Store and Play Services and are updated to the latest versions.
  5. I verified the APK is signed with the correct key - debug key for debug builds and my app signing key for release builds.
  6. I verified Firebase is set up correctly in my app.

Here's the relevant parts of the project's build.gradle:

buildscript {
    ext.kotlin_version = '1.3.72'

    repositories {
        google()
        maven { url 'https://maven.fabric.io/public' }
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.6.3'
        classpath 'com.google.gms:google-services:4.3.3'
        classpath 'io.fabric.tools:gradle:1.28.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter()
        }
    }
}

And the app's build.gradle:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'io.fabric'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 29

    defaultConfig {
        minSdkVersion 23
        targetSdkVersion 29
        // ...
    }

    signingConfigs {
        release {
            // ...
        }
    }

    buildTypes {
        debug

        release {
            signingConfig signingConfigs.release
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
    implementation 'com.google.firebase:firebase-analytics:17.4.0'
    implementation 'com.google.firebase:firebase-config:19.1.4'
    implementation 'com.google.firebase:firebase-messaging:20.1.6'
    implementation fileTree(dir: 'libs', include: ['PushIOManager-6.44.aar'])
    // etc...
}

I left out the bundles, flavors, other dependencies, etc. but hopefully this is enough. I did have this in my Application class's onCreate method:

// Initialize Fabric with Crashlytics
Fabric.with(this, new Crashlytics());

// Initialize Firebase
FirebaseApp.initializeApp(this);

I took those out because I believe they're no longer needed. Regardless, it makes no difference. I've gone over the Firebase documentation several times and can't figure out what I'm missing.

Edit: one of the dependencies I originally left out was Responsys. As soon as I removed it from my app, I stopped seeing the errors. I'm waiting to hear back from their support team.

like image 623
Big McLargeHuge Avatar asked Apr 30 '20 00:04

Big McLargeHuge


4 Answers

Firebase installation services (a new component used by Firebase Cloud Messaging) requires a valid Firebase combination options (specifically API key, Project ID, Application ID). Your app seems to have gotten an invalid combination along the way.

If you're initializing the app from a google-services.json, download the latest version of that file for the app from the Firebase console, and re-include it in your project. Manually verifying the contents of this file is error prone, so I'd just make a backup copy of the current file and replace it with the one you downloaded.

If that doesn't solve the problem, reach out to Firebase support with the google-services.json and other information for personalized help in troubleshooting.

like image 163
Frank van Puffelen Avatar answered Oct 22 '22 12:10

Frank van Puffelen


Background

Unfortunately, Google's frontend might incorrectly identify your API key as invalid. This can happen if your API key has not been used in a long time.

FirebaseInstallations is new infrastructure for Firebase services that makes use of the API key that you initialize Firebase with. If you recently updated your Firebase SDKs, FirebaseInstallations might have started using your API key which was not used before.


Remedy

If you have issues with your API key, you can create a new API key in the Cloud Console:

  • go to the Google Cloud Console
  • choose the relevant project (i.e. the project you use for your application)
  • open the menu and go to APIs & ServicesCredentials
  • on top of the page click on + CREATE CREDENTIALSAPI key
  • replace the API key in your application with the newly created API key

google-services.json

In case you are using the google-services.json config file from your Firebase Console, you first have to delete or restrict the API key used in your current google-services.json in order to make Firebase update config file and use a new API key.

  • Identify the API key in your google-services.json config file.
  • Confirm that the API key is creating the erroneous requests by checking its usage against the Firebase Installations API metrics page. The column Usage with this service of your API key should show a number greater than 0.
  • Delete that API key by clicking the bin symbol or add Application restrictions to that API key by clicking the pencil symbol. !!Warning!! Do not delete an API key that existing installations of your applications require for other Firebase services like Firebase Auth or Realtime-Database.

Wait a couple of minutes for Google servers to update. The next download of your google-service.json config file should contain a new API key.


Links

Other relevant links regarding API keys and the Firebase Installations API:

  • https://firebase.google.com/support/privacy/init-options
  • https://github.com/firebase/firebase-android-sdk/blob/master/firebase-installations/API_KEY_RESTRICTIONS.md
  • https://firebase.google.com/support/release-notes/android#2020-02-27
like image 39
Andreas Rayo Kniep Avatar answered Oct 22 '22 11:10

Andreas Rayo Kniep


For me, all provided solutions didn't work: I upgraded all dependencies, imported a new google-services.json which was exactly the same. I had no API restrictions in the https://console.cloud.google.com/apis/credentials/ . Downgrading was not an options because of other dependencies.

What solved it for me was to set the Key restrictions in https://console.cloud.google.com/apis/credentials/ to "None".

Hope this helps someone.

like image 2
Bruce Wayne Avatar answered Oct 22 '22 11:10

Bruce Wayne


  1. If You are using a Real device Check your Internet connection.

  2. If you are using android studio Emulator - Establish an internet connection by resetting the emulator.

    2.1. Open Tools -> AVD manager

Step 2.1

2.2. Wipe Data of the emulator Wipe Data of the emulator 2.2

  1. Run Project using fresh emulator.
like image 1
Ajith Ramesh Avatar answered Oct 22 '22 13:10

Ajith Ramesh