7

I am using Firebase PhoneAuth and getting the following error.

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.

W/Firebase-Installations: Error when communicating with the Firebase Installations server API. HTTP response: [400 Bad Request: {
  "error": {
    "code": 400,
    "message": "API key not valid. Please pass a valid API key.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developers console",
            "url": "https://console.developers.google.com"
          }
        ]
      }
    ]
  }
}
]
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Out of curiosity: Did you have to create a new project to fix this issue? – Andreas Rayo Kniep May 07 '20 at 02:25
  • 2
    No, I found that there were two projects with the same bundle ID. so I deleted the one that's not necessary. –  May 07 '20 at 18:39
  • where were these two projects with the same ID? On your device or firebase console? – Damandroid Mar 06 '21 at 23:14
  • I had shifted my android app from pointing to one firebase project to another (the older project was deleted) and it was failing with this error. I was able to fix this by deleting the app specific build folder and allowing it regenerate all the files, specifically -- `build/generated/res/google-services/{build-type}/values/values.xml`. [Reference](https://developers.google.com/android/guides/google-services-plugin) – user2555595 Jan 26 '22 at 07:22

5 Answers5

19

Background

The error says that the API key you use when initializing Firebase is not accepted by Google. You might in fact be using an invalid API key or Google might incorrectly identify your API key as invalid. The latter 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 you use when initializing Firebase. 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 current 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:

Andreas Rayo Kniep
  • 5,674
  • 2
  • 30
  • 30
  • In my case I encountered the exception when I replaced my old firebase android app with a new one. I have done all steps but still face that error. Then I release that I forgot to make some changes with the new app name. If you have created a new app, make sure you have replaced your old app name with the new one in your application. – genericUser Jan 24 '21 at 13:51
7

In my case, after struggling 5 hours, finally I figured out that Firebase Installations communicate with Firebase server by wrong API key which exist in values.xml file in this path \app\build\generated\res\google-services\debug\values not the API key in google-services.json file.

Because, I tried to run with updated google-services.json but it doesn't help.

So you should delete this values.xml file and it will be recreated again with the right API key automatically when you build and run.

Just delete this file and run.

Islam Ahmed
  • 668
  • 9
  • 19
2

If you are facing this issue in the Flutter app, then after updating the google-services.json file, you should delete the build folder from your project directory. Maybe it will work.

Abdul Mateen
  • 1,139
  • 1
  • 14
  • 21
0

In my case, I have generated SHA1 key using :

keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android

after that add this key and package name into Restrict usage to your Android apps in Google Cloud

That's it !

Sanjay
  • 574
  • 6
  • 16
0

I was trying to deploy same app from two different laptops. This was for 2 different developers working on the project. Firebase was giving me error on one PC inspite of adding SHA-1 key of 2nd laptop (Gradle Task Android - SigningReport). Then I copied the debug.keystore from .android folder of first laptop to 2nd one and it started working. Reason is you cannot access firebase app for same package from two different clients.