androidfluttergoogle-cloud-platformfirebase-analyticsgoogle-cloud-console

How to use a Google Cloud Project and Different Firebase Project Together For a Flutter App


Goal

I am currently working for a company where I need to access the People API from Google Cloud (for which I have set up OAuth) and also utilize Firebase's Analytics

Problem

I get this error:

google_sign_in plugin:PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException: 10: , null)

when I try to get access to the People API via OAuth. This happens only when I specify the dependencies for google play services in the gradle files (app and project level) [Check SDK Instructions for Firebase Android Project.].

Things I tried

  1. Giving all of the possible SHA keys for the app in the Google Cloud's credentials tab from this answer
  2. Given support email for OAuth
  3. Tried getting rid of the google play services dependencies from gradle files, this did solve the google_sign_in issue but Firebase Analytics stopped working and I get this error:

Missing google_app_id. Firebase Analytics disabled. See shortened_link_that_I_cant_post

Conclusion

Right now I am stuck with using only one of the two services. I removed Firebase from my Project and my App from Firebase console for now.

Packages Concerned

  1. google_sign_in: ^5.4.3: https://pub.dev/packages/google_sign_in
  2. extension_google_sign_in_as_googleapis_auth: ^2.0.7: https://pub.dev/packages/extension_google_sign_in_as_googleapis_auth
  3. googleapis: ^10.0.0: https://pub.dev/packages/googleapis
  4. firebase_core and firebase_analytics

Solution

  • if you have apply plugin: 'com.google.gms.google-services' inside android/app/build.gradle you comment this and it may solve the problem for you. I don't know if it will have a big effect on Firebase, but this solves the problem.

    You can read the docs https://firebase.google.com/docs/projects/multiprojects and search Deleting apply plugin: 'com.google.gms.google-services' from your app build.gradle

    Update 1: I found if you add at first or replace in oauth_client inside google-services.json at client_id where client_type=3 with web platform Google cloud credentials oauth client id, you can keep apply plugin: 'com .google.gms.google-services', google services code will generate google service values.xml with default_web_client_id attribute as your web client id, then this solves the problem.

    Update 2: After reading google_sign_in carefully.

    Update 24/05/2023: if you need read idToken when sign_in. You should to do Update 1