简体   繁体   English

无法解析符号 default_web_client_id GoogleSignInOptions Android Firebase

[英]Cannot resolve symbol default_web_client_id GoogleSignInOptions Android Firebase

My project works fine for last six month and app in play store.我的项目在过去六个月和 Play 商店中的应用程序运行良好。 For an update, I reopen the project shows default_web_client not resolved for the following piece of code.对于更新,我重新打开项目显示 default_web_client 未解决以下代码段。

GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestIdToken(getString(R.string.default_web_client_id))
                .requestEmail()
                .build();

I try the following methods,我尝试以下方法,

1.Clean and rebuild 1.清理和重建

2.Clear cache and restart 2.清除缓存并重启

3.Set getString(R.string.default_web_client_id) as empty string and run the project to generate 3.设置getString(R.string.default_web_client_id)为空字符串,运行项目生成

app/build/generated/res/google-services/{build_type}/values/values.xml

file as instruction from this link文件作为来自链接的说明

4.Replace empty string with getString(R.string.default_web_client_id) getString(R.string.default_web_client_id)getString(R.string.default_web_client_id)空字符串

Now I able to run the project and also able to take release build.现在我能够运行该项目,也能够进行发布构建。 But still, Cannot resolve symbol default_web_client_id.但是,仍然无法解析符号 default_web_client_id。

Any update would be helpful...任何更新都会有所帮助...

NB: Directly adding oauth_client->client_id will get an Error注意:直接添加oauth_client->client_id会报错

W/GoogleActivity: Google sign in failed
    com.google.android.gms.common.api.ApiException: 12500: 
        at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(Unknown Source) 

我已将 google 服务版本更新到项目级别 build.gradle 中的最新版本并且工作正常

classpath 'com.google.gms:google-services:4.2.0

I've got the same problem like you.我和你有同样的问题。 After update Android studio, it getting error.更新 Android Studio 后,出现错误。 There no need to fix because, Google try to make your app more and more secure.无需修复,因为 Google 会尝试使您的应用程序越来越安全。 If you try to create another value for default_web_client_id it will show error dupplicate variable.如果您尝试为 default_web_client_id 创建另一个值,它将显示错误重复变量。 To find the value of default_web_client_id * Change mode to Project -> app -> build -> generated -> google-services -> debug -> values -> values.xml.要找到 default_web_client_id 的值 * 将模式更改为 Project -> app -> build ->generated -> google-services -> debug -> values -> values.xml。 So, this cause no error when compiling, you no need to fix it.因此,这在编译时不会导致错误,您无需修复它。 Let wating google fix it later :D让等待谷歌稍后修复它:D

I get the same issue with my code also我的代码也遇到同样的问题

Cannot resolve symbol 'default_web_client_id'

i have tried clientID as the argument instead of R.string.default_web_client_id)我已经尝试将 clientID 作为参数而不是 R.string.default_web_client_id)

.requestIdToken(*My Client Id*)

and get the following in the debug code并在调试代码中获得以下内容

W/System.err: com.google.android.gms.common.api.ApiException: 12500:

I have update the google services to the latest in Project level build.gradle (google-serivces:4.2.0)我已将 google 服务更新到最新的项目级别 build.gradle (google-serivces:4.2.0)

!The Solution which worked for me! !对我有用的解决方案!

  1. Sign in to Developer Console登录开发者控制台

  2. Credentials > Create credentials >API key凭证 > 创建凭证 > API 密钥

  3. Download new google-services.json from Firebase (Project Overview > Users and Permissions > General scroll down从 Firebase 下载新的 google-services.json(项目概述 > 用户和权限 > 常规向下滚动
  4. Load new google-services.json into Project>app将新的 google-services.json 加载到 Project>app 中
  5. Replace Client id with new one generated from google-services.json oauth_client>client_id Note: Use client id with the client_type 3将客户端 ID 替换为从 google-services.json oauth_client>client_id 生成的新 ID注意:使用客户端 ID 和 client_type 3
.requestIdToken(*My New Client Id*)

6.Run your App :) 6.运行你的应用程序:)

This worked for me:这对我有用:

  1. Go to Google API Console and select the project you want转到Google API Console并选择您想要的项目

  2. Look at OAuth 2.0 client IDs.查看 OAuth 2.0 客户端 ID。 If you don't have already the web client api create one, type Web Client, you have to create one.如果您还没有 Web 客户端 api 创建一个,请键入 Web Client,您必须创建一个。 在此处输入图片说明

  3. Go to Firebase console, project settings and download the google-service.json file转到 Firebase 控制台,项目设置并下载 google-service.json 文件

  4. Replace the google-service file at your project.替换项目中的 google-service 文件。

  5. Try to compile.尝试编译。 Maybe be worthy to clean the the project or even the cache.也许值得清理项目甚至缓存。 If it still fails, then either:如果它仍然失败,那么要么:

    • you are not applying google services plugin correctly at your project grade file您没有在项目等级文件中正确应用Google 服务插件
    • the google-service-plugin is not generating the resource because it can't find the default id. google-service-plugin 没有生成资源,因为它找不到默认 ID。 This is happen to me, don't know why.这是我遇到的情况,不知道为什么。

      The web_default_client is generated from type 3 key, inside oauth_client element. web_default_client 是从 oauth_client 元素中的类型 3 键生成的。 This is how the json file should be for com.google.gms:google-services:4.3.2 :这是com.google.gms:google-services:4.3.2的 json 文件的格式:

 "oauth_client": [ { "client_id": "...", "client_type": 1, "android_info": { "package_name": "...", "certificate_hash": "..." } }, { "client_id": "<put here the Web type Oauth cliend id>, "client_type": 3 } ]

If it has not the client_type 3 node inside the array, add it.如果数组中没有 client_type 3 节点,则添加它。

A much simpler way is to pass the token id directly, like this:一种更简单的方法是直接传递令牌 ID,如下所示:

val gso = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(<put here the Oauth client ID for Web Application type>) but is not good if you have different firebase projects at different flavors.

Notes:笔记:

  • Firebase create automatically a web type OAuth ID named "Web client (auto created by Google Service)". Firebase 会自动创建一个名为“Web 客户端(由 Google 服务自动创建)”的 Web 类型 OAuth ID。 Couldn't make it recreate from firebase.无法从 firebase 重新创建它。
  • Android Type OAuth ids is created automatically when you add a new fingerprint to your firebase project.当您向 Firebase 项目添加新指纹时,会自动创建 Android 类型 OAuth id。

Before doing anything, I downloaded the most updated google-services.json file from Firebase> Project Settings and replaced it with the one in the project folder.在做任何事情之前,我从 Firebase> 项目设置下载了最新的 google-services.json 文件,并将其替换为项目文件夹中的文件。 Rebuild the project and It's gone.重建项目,它不见了。

I only opened res (generated) > values > values.xml and no more, the error ended.我只打开 res (generated) > values > values.xml 没有更多,错误结束了。

xxxxxxxx.apps.googleusercontent.com xxxxxxxx.apps.googleusercontent.com

Just come back to the previous classpath version from google services: In my case I had to change from classpath 'com.google.gms:google-services:4.3.10' to classpath 'com.google.gms:google-services:4.3.8' in the build.gradle panel.刚刚从谷歌服务回到以前的类路径版本:在我的情况下,我不得不从类路径 'com.google.gms:google-services:4.3.10' 更改为类路径 'com.google.gms:google-services:4.3 .8' 在 build.gradle 面板中。 Sometimes the google services updates do not work properly and that is a good developer headache.有时 google 服务更新无法正常工作,这是一个很好的开发人员头痛。

None of these solutions worked for me这些解决方案都不适合我

I tried to put the plugin at the bottom of my build.gradle and the other solutions.我试图将插件放在我的 build.gradle 和其他解决方案的底部。

What worked for me was to access to default_web_client_id string programmatically.对我default_web_client_id是以编程方式访问default_web_client_id字符串。

In kotlin I created an extension to obtain a resource string在 kotlin 中,我创建了一个扩展来获取资源字符串

fun Context.getStringFromName(name: String): String {
 return getString(
    resources.getIdentifier(
        name,
        "string",
        packageName
    ))
}

and then进而

val defaultWebClientId = context.getStringFromName("default_web_client_id")

worked like charm for me!对我来说就像魅力一样!

Ok first let me tell you why this occur because most of the time developer can face it. 好的,首先让我告诉你为什么会这样,因为大多数时候开发人员都可以面对它。 As you integrate the Friebase Auth with the google and after that you close the project you default_web_client_id will be gone. 当您将Friebase Auth与google集成后,关闭项目后,default_web_client_id将会消失。

And the saddest part is you can't add yourself. 而最可悲的部分是你无法添加自己。

So what to do now: 那么现在该怎么办:

Solution: 解:

go to res-->vlaues-->strings 转到res - > vlaues - >字符串

add the Client id(xxxxxx) 添加客户端ID(xxxxxx)

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

You can find this here how to add 你可以在这里找到如何添加

CLICK THIS LINK TO WATCH VIDEO FOR BETTER AND EASY SOLUTION 点击此链接观看视频,获得更好,更轻松的解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 Firebase 的 Android Codelab 中解析符号 default_web_client_id - Cannot resolve symbol default_web_client_id in Firebase's Android Codelab 无法在 android studio 中解析 default_web_client_id - cannot resolve default_web_client_id in android studio 无法解析符号“default_web_client_id”错误,但应用程序运行成功 - Cannot resolve symbol 'default_web_client_id' Error , But App Runs Successfully Android工作室中的谷歌登录按钮whit firebase,错误:找不到符号变量default_web_client_id - Google login button whit firebase in android studio, error: cannot find symbol variable default_web_client_id Android:无法解析符号GoogleSignInOptions - Android: Cannot resolve symbol GoogleSignInOptions 为什么在Android Studio 3.3中登录Google时找不到default_web_client_id - why do not found default_web_client_id when Google Login in Android Studio 3.3 google-services.json如何取代default_web_client_id? - How does google-services.json replace default_web_client_id? 检查您的 google-services 插件配置,未填充 default_web_client_id 字符串 - Check your google-services plugin configuration, the default_web_client_id string wasn't populated Android:Firebase 中的“无法解析符号‘addValueEventListener’” - Android: “Cannot Resolve symbol 'addValueEventListener'” in Firebase Android Studio - 无法解析符号&#39;firebase&#39; - Android Studio - Cannot resolve symbol 'firebase'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM