简体   繁体   中英

app crash when add google login firebaseui

When we add this line new AuthUI.IdpConfig.GoogleBuilder().build() , the app crashes and shows this error "Check your google-services plugin configuration, the default_web_client_id string wasn't populated"
What to do? I have tried almost all solutions that are suggested in GitHub and StackOverflow but my problem is not solved. My project was working with Google login Firebase UI and I don't know why it is not working now.
If I remove googlebuilder then the app works without any problems.

implementation 'com.firebaseui:firebase-ui-auth:4.3.2'



 dependencies {
        classpath 'com.android.tools.build:gradle:3.3.2'
        classpath 'io.fabric.tools:gradle:1.25.4'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files     // in the individual module build.gradle files
       // classpath 'com.google.gms:google-services:3.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
       // classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'


    }

I think its an issue in firebase console. I use two different firebase projects to separate dev and prod environments and I started getting this error on production today.

I compared the two generated google-services.json files and found out the one that I generated today was missing another object in the oauth_client array

This one works - default_web_client_id is generated:

  "oauth_client": [
    {
      "client_id": "blabalbal-blablabal",
      "client_type": 1,
      "android_info": {
        "package_name": "haha",
        "certificate_hash": "ahaha"
      }
    },
    {
      "client_id": "hahah",
      "client_type": 3
    }
  ],

I generated this one today and default_web_client_id is not generated from this one

  "oauth_client": [
    {
      "client_id": "bababab",
      "client_type": 1,
      "android_info": {
        "package_name": "babab",
        "certificate_hash": "blablbalb"
      }
    }
  ],

So the one that works has this extra object:

  {
      "client_id": "hahah",
      "client_type": 3
   }

where the client_id is located in google cloud console -> APIs & Services -> Credentials -> OAuth 2.0 Client IDs -> "Web client (auto created by Google Service)"

So I paste that object back in as a temporary solution...

The approach that worked for me was as follows:

  1. Login to Google Cloud Console
  2. From the menu on the left, select APIs and Services -> Credentials
  3. Copy the client ID from the Web Client (auto-created by Google Service) under the "OAuth 2.0 client IDs" section
  4. Back in Android Studio, in res -> values -> Strings.xml, create an entry of the form

     <string name="default_web_client_id" translatable="false">XXXXXXX</string> 

(where XXXXXXX is the client ID you copied from the console in step 3

  1. Recompile, the application should work without any problems now.

Instead of manually editing google-services.json :

  1. Generate a new Client ID for Web application from Google cloud console > API and Services > Credentials > OAuth 2.0 client IDs . Important that you select Web application not Android.
  2. Update (or add) your debug, app signing and upload SHA-1 certificate fingerprints to your firebase settings.
  3. Now download the latest google-services.json from your firebase settings.
  4. Replace the old google-services.json in your Project > app with the new one.
  5. Now build your app. These steps will make Firebase auto-generate a new Android client in OAuth 2.0 that will include the Client ID for Web application you have manually created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM