添加谷歌登录firebaseui时应用程序崩溃

问题描述 投票:1回答:3

当我们添加此行new AuthUI.IdpConfig.GoogleBuilder().build()时,应用程序崩溃并显示此错误“检查您的google-services插件配置,未填充default_web_client_id字符串” 该怎么办?我已经尝试了GitHub和StackOverflow中建议的几乎所有解决方案,但我的问题没有解决。我的项目正在使用Google登录Firebase用户界面,我不知道为什么它现在无法运行。 如果我删除googlebuilder,那么该应用程序可以正常运行。

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'


    }
java android firebase-authentication firebaseui
3个回答
0
投票

我认为这是firebase控制台中的一个问题。我使用两个不同的firebase项目来分离dev和prod环境,我今天开始在生产中遇到这个错误。

我比较了两个生成的google-services.json文件,发现我今天生成的文件丢失了oauth_client数组中的另一个对象

这个工作 - 生成default_web_client_id

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

我今天生成了这个,并且default_web_client_id不是从这个生成的

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

所以有效的那个有这个额外的对象:

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

client_id位于谷歌云控制台 - > API和服务 - >凭据 - > OAuth 2.0客户端ID - >“Web客户端(由Google服务自动创建)”

所以我将该对象粘贴回作为临时解决方案......


-1
投票

对我有用的方法如下:

  1. 登录Google Cloud Console
  2. 从左侧菜单中,选择API和服务 - >凭据
  3. 从“OAuth 2.0客户端ID”部分下的Web客户端(由Google服务自动创建)复制客户端ID
  4. 回到Android Studio,在res - > values - > Strings.xml中,创建一个表单的条目 <string name="default_web_client_id" translatable="false">XXXXXXX</string>

(其中XXXXXXX是您在步骤3中从控制台复制的客户端ID

  1. 重新编译,应用程序现在应该没有任何问题。

-1
投票

而不是手动编辑google-services.json

  1. 从Google云控制台> API和服务>凭据> OAuth 2.0客户端ID生成新的Client ID for Web application。重要的是您选择Web应用程序而不是Android。
  2. 更新(或添加)您的调试,应用程序签名并将SHA-1证书指纹上传到您的firebase设置。
  3. 现在从您的firebase设置下载最新的google-services.json
  4. 用新的替换Project> app中的旧google-services.json
  5. 现在构建您的应用程序这些步骤将使Firebase在Android client中自动生成一个新的OAuth 2.0,其中包括您手动创建的Client ID for Web application
© www.soinside.com 2019 - 2024. All rights reserved.