Error when communicating with the Firebase Installations server API - 403 Forbidden
Asked Answered
G

3

8

A have a big project with a lot of dependencies including Firebase.

Now com.google.firebase:firebase-messaging has version 17.3.3. I want to update it to the 20.2.1.

I'm getting next error after app has started:

Firebase-Installations: Error when communicating with the Firebase Installations server API. HTTP response: [403 Forbidden: {
  "error": {
    "code": 403,
    "message": "Requests from this Android client application com.example are blocked.",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developer console API key",
            "url": "https://console.developers.google.com/project/61947752567/apiui/credential"
          }
        ]
      }
    ]
  }
}
]
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.

We use google-services.json to configure FCM in our app. We do not use FirebaseOptions in code.

I've noticed that the problem is connected with updating FCM to 20.1.1. And what Google says about FCM 20.1.1:

The Firebase Cloud Messaging and Firebase Instance ID SDKs now transitively depend on the Firebase installations SDK. If you use Cloud Messaging and update your dependencies to their latest versions, make sure that push notifications still work as expected.

I read an instruction from Google but no success. What I tried:

  1. Re-download google-services.json from Firebase console. No success because it's identical.
  2. Apply instruction about API-Key restrictions inside Firebase Console. It turned out that we don't have any restrictions ("Don't restrict key" option is checked).
  3. Update all of Firebase (including firebase-perf) and GCM dependencies to the latest versions. No changes.
  4. Set App ID, project ID and API-Key with FirebaseOptions right in the code before calling initializeApp method.

It also turned out that installed from APK application works correctly! If I use .aab (App Bundle) - I'm getting this error. I also use the latest bundletool.

firebase-messaging is included into our main app-module and it's one of the main features of application. I'm not talking about dynamic modules - the problem is with the main module.

I can't setup FCM again because there are a lot of users who use this application now. Also I can't understand why I have to set valid options (API key, Project ID, Application ID) if this options work great for last few years and google-services.json has not changes.

I will be grateful for any ideas.

P.S. I can't use FCM 20.1.0 because I need to integrate ML Kit dependency. It works only with actual version of FCM and crashes with FCM 20.1.0

Gunstock answered 23/6, 2020 at 12:20 Comment(2)
Did you manage to find out what was the problem? I'm facing the same issue and generating an APK doesn't seem to solve it either.Diagnosis
Unfortunately I had to integrate old ML Kit dependency (from december 2019 if I'm not mistaken)Gunstock
G
1

In my case, I made 2 applicatiions in 1 firebase project. google-services.json downloaded from firebase has 2 client informations. I get the same error with this setup.

{
  "project_info": {
    "project_number": "xxxxxx",
    "firebase_url": "xxxxxx.firebaseio.com",
    "project_id": "xxxxxx",
    ......
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "xxxxxx",
        "android_client_info": {
          "package_name": "application-1"
        }
      },
      .......
      "api_key": [
        {
          "current_key": "(API-Key for application1)"
        },
        {
          "current_key": "(API-Key for application2)"
        }
      ],
      .......
    },
    {
      "client_info": {
        "mobilesdk_app_id": "xxxxxx",
        "android_client_info": {
          "package_name": "application-2"
        }
      },
      ......
      "api_key": [
        {
          "current_key": "(API-Key for application1)"
        },
        {
          "current_key": "(API-Key for application2)"
        }
      ],
      ......
    }
  ],
  "configuration_version": "1"
}

I edited google-services.json and made it simple for application-2. This works well.

{
  "project_info": {
    "project_number": "xxxxxx",
    "firebase_url": "xxxxxx.firebaseio.com",
    "project_id": "xxxxxx",
    ......
  },
  "client": [
    {
      "client_info": {
        "mobilesdk_app_id": "xxxxxx",
        "android_client_info": {
          "package_name": "application-2"
        }
      },
      ......
      "api_key": [
        {
          "current_key": "(API-Key for application2)"
        }
      ],
      ......
    }
  ],
  "configuration_version": "1"
}
Gesture answered 31/12, 2022 at 0:58 Comment(0)
S
0

Sometimes the project needs a simple rebuild/clean as precompiled outdated files (json/xml) stays in the precompiled version of the project.

Run in Android IDE: Build -> "Clean Project" and "Build" -> "Rebuild Project".

This won't help in all cases. Redownloading the google-services.json file may be better instead of editing/checking it manually. Don't forget to rebuild/clean after replacing the file.

Stovall answered 28/6, 2022 at 9:24 Comment(0)
E
0

Maybe you met the same problem as me. Go to https://console.cloud.google.com/apis/credentials check the api key's "Android restrictions". The debugging version's fingerprint might be deleted previously for one day google sent email to ask you to(for safety reason or so). Add it back and later it will work again.

Eventuality answered 25/6 at 8:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.