Cannot resolve symbol default_web_client_id in Firebase's Android Codelab
Asked Answered
A

26

45

I am trying to learn Firebase, so I went through the Android Codelab. The project they gave me however, had an error:

Cannot resolve symbol default_web_client_id

And I didn't know how to solve it, since I didn't know the value of default_web_client_id or what it is. It is in the onCreate() method: SigninActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);
    mFirebaseAuth = FirebaseAuth.getInstance();

    // Assign fields
    mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);

    // Set click listeners
    mSignInButton.setOnClickListener(this);

    // Configure Google Sign In
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestIdToken(getString(R.string.default_web_client_id))
            .requestEmail()
            .build();
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
}

I have no idea what it is, what's its value is, and why is it giving me this error. I haven't changed anything so far except for adding the google-services.json. I have added my SHA-1 and enabled Google in the console.

Amhara answered 14/6, 2016 at 11:20 Comment(4)
you have to register to the Auth 2.0 from developer.google.com. use this: console.developers.google.com/apis/credentials?project=_ to generate a Auth 2.0 keyPushkin
@M.WaqasPervez I have already added my SHA1 key, is Auth2.0 different?Amhara
Can you make sure that you have this line apply plugin: 'com.google.gms.google-services' at the bottom of your app/build.gradle, as documented here?Burgonet
ref this : chetan-garg36.medium.com/…Wamble
M
68

Sometimes there is issue while parsing google-services.json. I have reported this issue with to concerned team.

Meanwhile follow below step to fix this issue to get going further -

1) Open google-services.json file -> client -> oauth_client -> client_id

2) Copy this client ID and hardcode this .requestIdToken("your ID")

It would allow to request "IdToken" via GoogleSignInAccount post successful google login and to authorize your credential with firebase.

EDIT

Try deleting and recreating the project and re-importing new google-service.jsonin your Android project

Matchbox answered 14/6, 2016 at 13:11 Comment(8)
This is what I see in oauth_client: "oauth_client": [] there is no ID, and I can't find client_id anywhere in the file either.Amhara
@AbAppletic try adding SHA1 key and re-downloading the config file from firebase console - project settingMatchbox
Still nothing. I have added my SHA1Amhara
@AbAppletic if you have just started with the project. try deleting and re-creating a new project -> add android app. This should work. Even if does not work try contacting firebase team.Matchbox
Thanks, it worked. Deleting the app then remaking it fixed the problem from the beginning, didn't have to hardcode anything.Amhara
What if you have more than 1 client ids? I just looked at my project just now. There is one for client type 1 and client type 3. What does these mean?Fancywork
This isn't quite right. You need to make sure client_type is 3. See my answer.Monopetalous
got error ApiException: 12500: at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatusGravel
W
20

A more generic solution would be to add the google-services.json into the app's root directory.
And add

apply plugin: 'com.google.gms.google-services at the end of build.gradle file.

Explanation

When the app builds the key value pair strings from google-services.json config file are then placed into the values.xml file to make them globally available for use from anywhere in your code. This saves us from hard coding the client_id in your code.

Note

Do not add the default_web_client_id with client_id as its value in the strings.xml in order to avoid the error of duplication, Error: Duplicate resourceslater on when you run your code.

Woolgathering answered 7/8, 2016 at 18:20 Comment(2)
build worked after making this update and then running invalidate cache & restart. much nicer than having to edit the .json file - thanksSedation
Did not work in my case. I am using Android Studio 4.1Underhanded
P
13
  1. google-services.json in ./app/ folder
  2. Add in project-level build.gradle the following:
    buildscript {
    ...
    dependencies {
        ...
        classpath 'com.google.gms:google-services:4.3.5'
    }
  1. In app-level build.gradle, apply the plugin:
    apply plugin: 'com.google.gms.google-services'

This is the annoying thing I found. Upgrading it from 4.3.5 to anything higher than that makes Android Studio unable to detect the generated values.xml file.

Pheni answered 6/10, 2021 at 3:42 Comment(2)
Same com.google.gms:google-services:4.3.10 not working ,so I implemented 4.3.5Renaterenato
Damn, this really works. My build didn't fail by that error so I was ignoring it all along thinking its a glitch somewhere.Septic
N
12

After a time searching the "smart" fix without insert directly the client_id, following this answer from FirebaseUI project I just need to add the next line in app/build.gradle:

implementation 'com.firebaseui:firebase-ui-auth:4.3.2'
Nolin answered 5/4, 2019 at 7:6 Comment(3)
That helps to resolve an error during build. However, yet it does not automatically put ID from json file to values.xml... So it works but does not login :(Gilthead
Yes it worked for me, thank you so much and it's better than just insert the client_id directlyContort
still there. in 2023. Google is amazing in hardliving.Diorama
S
7

Apparently R.string.default_web_client_id is generated from the IDE build

I had assumed we are supposed to manually add it - time consuming mistake

https://developers.google.com/android/guides/google-services-plugin

The google-services plugin has two main functions: 1) Process the google-services.json file and produce Android resources that can be used in your application's code.

~~~~

The main result of the JSON processing is to produce two XML files which you can reference as Android resources in your Java code.

And so - after successful build, if you search the IDE for string default_web_client_id , you will see one result is values.xml under the /generated folder, and there it has the values for your firebase config, like the example below.

Actually seeing that file, helped to clarify things here

<resources>
    <string name="default_web_client_id" translatable="false">123.apps.googleusercontent.com</string>
    <string name="firebase_database_url" translatable="false">https://123.firebaseio.com</string>
    <string name="gcm_defaultSenderId" translatable="false">123</string>
    <string name="google_api_key" translatable="false">123</string>
    <string name="google_app_id" translatable="false">123</string>
</resources>
Sedation answered 27/8, 2018 at 18:7 Comment(1)
This is solution to my problem, I just did rebuild of project & it worked.Predecease
S
4

**The main issue with this right now for me was to make sure to download the json file from the same location. If the initial one came from the firebase console do not use the api console to get the file, and vise versa. The files are not the same **

Schecter answered 1/12, 2017 at 19:54 Comment(4)
Thanks for your comment. I just tried to google download json file from API, but for now all the links refer to download page of Firebase :(Gilthead
sorry to hear that, but it kind of depends where the original file came from. if the project was originally a firebase project then use that file. if the project came from the api console download and use that file. Don't mix them. At the time of this post that was true. Unfortunately it is a moving target.Schecter
Well anyway for now I hardcoded the web id, at least it works, even though hardcodedGilthead
also sent an issue to firebase, they didn't respond at all - so in the future I would move all the backend from firebase to something more reliableGilthead
M
3

I already have google-services.json downloaded and parsed, but still it doesn't find the string.

I noticed that my oauth_client had a key with client_type of 1 and that's all. In the Google API console, I only had an Android key.

So, you need to go to the API console and generate a Web Server key. Then, download your google-services.json again, and you'll have a oauth_client with a type of 3.

Now, the plugin will generate a string called default_web_client_id.

Monopetalous answered 2/3, 2017 at 16:11 Comment(0)
B
3

I had the same problem or similar,

Make sure that in your google-services.json you have:

...    
"client": [
        ...
          "oauth_client": [
            ...
            {
              "client_id": "YOUR WEB CLIENT ID",
              "client_type": 3
            }     
...

For some reason the file downloaded from firebase console doesn't include it.

After adding the entry in the google-services.json file, everything started working as expected.

google-services-plugin documentation

Bernard answered 8/4, 2019 at 12:12 Comment(0)
E
3

Download your newest google-services.json. List of client_id is present for OAuth 2.0 client IDs in your Google Cloud Credentials.

Then check whether it contains client_id with "client_type" : 3 or not. If not, you need to create a new one:

  1. Open the Credentials page in the API Console.
  2. Click Create credentials -> OAuth cliend ID. Then chose type Web application.
  3. Wait 2-3 minutes, refresh Firebase Console & download your google-services.json again. It should contain client_id with "client_type" : 3 now.

Clean & rebuild your project to apply new API config.


The client_id with "client_type" : 3 is usually inside oauth_client tag, not services or other_platform_oauth_client.

If you fall to this case & cannot build the project, try copy your client_id to oauth_client tag and rebuild again.

"client": [
        ...
        "oauth_client": [
            ...
            {
              "client_id": "YOUR WEB CLIENT ID",
              "client_type": 3
            }
        ]
]     
Ex answered 11/7, 2019 at 15:22 Comment(0)
G
2

In addition to the Dexto's Answer I would like to mention one more thing In the JSON file you will get two kind of client id

One Which is having client_type value 1 and Another with the client_type value 3 Make sure you specified the client_id of client_type which has value of 3

Grampositive answered 28/10, 2018 at 10:41 Comment(0)
P
2
classpath 'com.google.gms:google-services:4.1.0'

has a problem. instead use:

classpath 'com.google.gms:google-services:4.2.0'
Poorly answered 30/3, 2019 at 8:22 Comment(0)
Z
1

I also had the same issue, make sure "google-services.json" is in your app directory. Then simply rebuild the project from "Build -> Rebuild Project"

Since the string resource "default_web_client_id" is auto-generated, it will be resolved once you rebuild the project

Zinkenite answered 9/1, 2021 at 14:24 Comment(0)
P
1

for my case: The lib was old so I go get the last lib at: https://firebase.google.com/docs/auth/android/firebaseui

put in dependency: implementation 'com.firebaseui:firebase-ui-auth:7.2.0'

along with what currently there

// Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:26.7.0')

// When using the BoM, you don't specify versions in Firebase library dependencies implementation 'com.google.firebase:firebase-auth-ktx'

and it is fixed

Prudenceprudent answered 30/12, 2021 at 16:47 Comment(1)
Not fixed for me.Procora
H
0

Try downloading your .json file again after changing the configuration in the Firebase console. Use this newer configuration file, not the old one.

Hols answered 2/2, 2017 at 7:7 Comment(0)
K
0

Fixed after using this link to create my backend id to Google API.

https://developers.google.com/identity/sign-in/android/start-integrating#get_your_backend_servers_oauth_20_client_id

  • 1- Open the Credentials page in the API Console.

  • 2- The Web application type client ID is your backend server's OAuth 2.0 client ID.

After this, you can re-download your json file and android studio will automatically matching your string id.

Kaiserdom answered 22/4, 2017 at 10:28 Comment(0)
S
0

I know it is late to answer but hope this will help someone in the future.

To access there is no need to hard code default_web_client_id in app.

To access default_web_client_id in Android App from google-services.json, we have to add SHA1 key under FireBase project Settings.

Go to Firebase Console > Open Project > Select App > Add Fingerprint.

After this copy generated google-services.json to project.

After this you will see the difference in json file as below:

Before :

"oauth_client": []

After :

"oauth_client": [
    {
      "client_id": "23........4-asdj...........................asda.googleusercontent.com",
      "client_type": 1,
      "android_info": {
        "package_name": "com.abc.xyz",
        "certificate_hash": "asjhdashhs"
      }
    },.....

This will solve your issue.

Sayette answered 14/8, 2019 at 12:24 Comment(0)
H
0

Generic solution for this is to apply google play services plugin at the end of build.gradle like this

  apply plugin: 'com.android.application'

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.0"

    buildFeatures {
        dataBinding true
    }

    defaultConfig {
        applicationId "xxxxxx"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'



    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    // For Common Dimension
    implementation 'com.intuit.sdp:sdp-android:1.0.5'
    implementation 'com.intuit.ssp:ssp-android:1.0.5'
    // Retrofit and Gson
    implementation 'com.google.code.gson:gson:2.8.6'
    implementation 'com.squareup.retrofit2:retrofit:2.6.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.retrofit2:converter-scalars:2.6.1'
    // Rx Java and Dagger
    implementation 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
    implementation 'io.reactivex:rxandroid:1.2.1'
    implementation 'io.reactivex:rxjava:1.1.6'

    implementation 'com.google.dagger:dagger:2.24'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.24'
    compileOnly 'javax.annotation:jsr250-api:1.0'
    compileOnly 'org.glassfish:javax.annotation:10.0-b28'
    // Glide Image Loading
    implementation 'com.github.bumptech.glide:glide:4.9.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'com.android.support:design:30.0.0'
    implementation 'com.android.support:recyclerview-v7:30.0.0'
    implementation 'com.android.support:cardview-v7:30.0.0'
    implementation 'com.android.support:multidex:1.0.3'

    /*Jsoup*/
    implementation 'org.jsoup:jsoup:1.9.1'

    /*Firebase*/
    implementation 'com.google.firebase:firebase-core:17.5.0'
    implementation 'com.google.firebase:firebase-config:19.2.0'
    implementation 'com.google.firebase:firebase-messaging:20.2.4'
    implementation 'com.google.firebase:firebase-database:19.3.1'
    implementation 'com.google.firebase:firebase-auth:19.3.2'
    implementation 'com.firebaseui:firebase-ui-storage:6.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-analytics:17.5.0'

    /*location and google map*/
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'
    implementation 'com.google.android.gms:play-services-auth:18.1.0'

    /*Circle Image View*/
    implementation 'de.hdodenhof:circleimageview:3.0.1'
    implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
    implementation "com.android.support:design:30.0.0"
    implementation 'com.facebook.android:facebook-android-sdk:5.15.3'

}

apply plugin: 'com.google.gms.google-services'
Hersh answered 17/8, 2020 at 17:45 Comment(0)
I
0

in my case I forgot to add

id 'com.google.gms.google-services'

to the plugin of build.gradle(:app)

Isochronal answered 11/11, 2020 at 22:28 Comment(0)
B
0

Use BOM to use the compatible version of firebase.

In your module (app-level) Gradle file:

dependencies {
  // ...

  // Import the Firebase BoM
  implementation platform('com.google.firebase:firebase-bom:29.3.0')

  // When using the BoM, you don't specify versions in Firebase library dependencies

  // Declare the dependency for the Firebase SDK for Google Analytics
  implementation 'com.google.firebase:firebase-analytics'

  // Declare the dependencies for any other desired Firebase products
  // For example, declare the dependencies for Firebase Authentication and Cloud Firestore
  implementation 'com.google.firebase:firebase-auth'
  implementation 'com.google.firebase:firebase-firestore'
}

Source: https://firebase.google.com/docs/android/setup?authuser=0&hl=en#add-sdks

Blackbird answered 9/4, 2022 at 18:19 Comment(0)
M
0

What I have done is just Rebuild the project and that works for me.

Yes I have checked before doing that my google-services.json file is on the proper place and it is having client_type = 3 as key and client_id = "Your Client Id" as well.

Consider here "Your Client Id" = Your app's client ID which you will get from the firebase.

Malagasy answered 27/5, 2023 at 17:55 Comment(0)
A
0

In my case, google-services.json file "client" -> "oauth_client" -> has no details.

"oauth_client": [
    { 
    }

],

Therefore I download google-services.json file from my Firebase Project Settings and replace the file in my project.

Altocumulus answered 30/3 at 4:55 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Justen
P
0

I see some workarounds here, Root cause: When we create the firebase project and download the google-services.json file, firebase authentication is not enabled and thus google-services.json won't contain oauth id'

Correct solution:

  1. Enable GoogleAuthentication in Firebase as shown in image below:

enter image description here

  1. Download google-services.json again.
Prussiate answered 5/5 at 8:6 Comment(0)
A
-1

Update your project level build.gradle file with the following code:

buildscript {
repositories {
    google()
    jcenter()
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.2'
    classpath 'com.google.gms:google-services:4.2.0'
}}
allprojects {
repositories {
    google()
    jcenter()
    maven { url "https://maven.google.com"}  
}}
task clean(type: Delete) {
delete rootProject.buildDir }

More Details:answerdone.com

Approver answered 23/7, 2019 at 20:24 Comment(0)
E
-1

For me the problem was because I was using minSdkVersion 15, updating to 16 has solved my problem.

Ecclesiastical answered 11/7, 2020 at 19:10 Comment(0)
H
-1

I have searched for it whole day, I already have pasted that json file inside App and rebuild many times, but the android studio still marks it as error in ide.

Solution: just run the project, ignore the error, it will work, it is an IDE bug.

Haberdasher answered 24/11, 2021 at 13:57 Comment(0)
T
-2
implementation platform('com.google.firebase:firebase-bom:29.0.0')

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

Put these lines into build.gradle(projectName)

Tinge answered 26/12, 2021 at 5:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.