Cannot resolve symbol default_web_client_id GoogleSignInOptions Android Firebase

寵の児 提交于 2019-12-19 03:58:44

问题


My project works fine for last six month and app in play store. For an update, I reopen the project shows default_web_client not resolved for the following piece of code.

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

2.Clear cache and restart

3.Set getString(R.string.default_web_client_id) as empty string and run the project to generate

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)

Now I able to run the project and also able to take release build. But still, Cannot resolve symbol default_web_client_id.

Any update would be helpful...

NB: Directly adding oauth_client->client_id will get an Error

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) 

回答1:


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)

.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)

!The Solution which worked for me!

  1. Sign in to Developer Console

  2. Credentials > Create credentials >API key

  3. Download new google-services.json from Firebase (Project Overview > Users and Permissions > General scroll down
  4. Load new google-services.json into 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
.requestIdToken(*My New Client Id*)

6.Run your App :)




回答2:


I have updated google services version to the latest in Project level build.gradle and worked fine

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



回答3:


I've got the same problem like you. After update Android studio, it getting error. There no need to fix because, Google try to make your app more and more secure. If you try to create another value for default_web_client_id it will show error dupplicate variable. To find the value of default_web_client_id * Change mode to 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




回答4:


This worked for me:

  1. Go to Google API Console and select the project you want

  2. Look at OAuth 2.0 client IDs. If you don't have already the web client api create one, type Web Client, you have to create one.

  3. Go to Firebase console, project settings and download the google-service.json file

  4. Replace the google-service file at your project.

  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
    • the google-service-plugin is not generating the resource because it can't find the default id. This is happen to me, don't know why.

      The web_default_client is generated from type 3 key, inside oauth_client element. This is how the json file should be for com.google.gms:google-services:4.3.2:

"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.

A much simpler way is to pass the token id directly, like this:

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)". Couldn't make it recreate from firebase.
  • Android Type OAuth ids is created automatically when you add a new fingerprint to your firebase project.



回答5:


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.

And the saddest part is you can't add yourself.

So what to do now:

Solution:

go to res-->vlaues-->strings

add the Client 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



来源:https://stackoverflow.com/questions/54323451/cannot-resolve-symbol-default-web-client-id-googlesigninoptions-android-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!