23

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Ali Bdeir
  • 4,591
  • 9
  • 46
  • 101
  • you have to register to the Auth 2.0 from developer.google.com. use this: https://console.developers.google.com/apis/credentials?project=_ to generate a Auth 2.0 key – M.Waqas Pervez Jun 14 '16 at 11:24
  • @M.WaqasPervez I have already added my SHA1 key, is Auth2.0 different? – Ali Bdeir Jun 14 '16 at 12:40
  • 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](https://firebase.google.com/docs/android/setup#add_the_sdk)? – Frank van Puffelen Jun 14 '16 at 13:48

19 Answers19

44

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

Dexto
  • 951
  • 7
  • 18
  • 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. – Ali Bdeir Jun 14 '16 at 13:41
  • 1
    @AbAppletic try adding SHA1 key and re-downloading the config file from firebase console - project setting – Dexto Jun 14 '16 at 13:47
  • Still nothing. I have added my SHA1 – Ali Bdeir Jun 14 '16 at 13:52
  • @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. – Dexto Jun 14 '16 at 13:55
  • Thanks, it worked. Deleting the app then remaking it fixed the problem from the beginning, didn't have to hardcode anything. – Ali Bdeir Jun 14 '16 at 14:10
  • 2
    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? – Kevin Tan Aug 08 '16 at 16:11
  • This isn't quite right. You need to make sure client_type is 3. See my answer. – Greg Ennis Mar 02 '17 at 16:18
  • got error ApiException: 12500: at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus – Subin Babu Jan 23 '19 at 09:19
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.

Community
  • 1
  • 1
user1523292
  • 266
  • 1
  • 8
5

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>
Gene Bo
  • 8,869
  • 6
  • 70
  • 118
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 **

  • 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 :( – Liker777 Mar 01 '21 at 05:31
  • 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. – keepTrackOfYourStack Mar 03 '21 at 14:36
  • Well anyway for now I hardcoded the web id, at least it works, even though hardcoded – Liker777 Mar 03 '21 at 18:13
  • 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 reliable – Liker777 Mar 03 '21 at 18:14
  • 1
    thats exactly right!! – keepTrackOfYourStack Mar 05 '21 at 23:22
2

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.

Greg Ennis
  • 13,126
  • 1
  • 64
  • 70
2
classpath 'com.google.gms:google-services:4.1.0'

has a problem. instead use:

classpath 'com.google.gms:google-services:4.2.0'
Avnish kumar
  • 902
  • 1
  • 10
  • 14
2

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'
Jairo Martínez
  • 155
  • 1
  • 7
  • 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 :( – Liker777 Feb 28 '21 at 17:02
2

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

Luis
  • 148
  • 1
  • 4
1

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

AgentP
  • 3,133
  • 2
  • 15
  • 27
0

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

RedBassett
  • 2,955
  • 3
  • 27
  • 46
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.

faruk
  • 4,165
  • 3
  • 24
  • 40
Johnny
  • 2,082
  • 1
  • 14
  • 26
0

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
            }
        ]
]     
nhoxbypass
  • 8,877
  • 9
  • 39
  • 62
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.

Rahul
  • 326
  • 4
  • 17
-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

-1

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

Mauricio Reis
  • 76
  • 1
  • 7
-1

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'
-1

in my case I forgot to add

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

to the plugin of build.gradle(:app)

-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

Saravanan
  • 91
  • 6
-2

Download again google-services.json file from the firebase project that you connected with your android project and replace it in app/src directory. And then select clean project option which is in build sub menu. This worked for me.