Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol default_web_client_id in Firebase's Android Codelab

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.

like image 449
Ali Bdeir Avatar asked Jun 14 '16 11:06

Ali Bdeir


12 Answers

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

like image 164
Dexto Avatar answered Oct 03 '22 19:10

Dexto


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.

like image 45
user1523292 Avatar answered Oct 03 '22 18:10

user1523292


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'
like image 45
Jairo Martínez Avatar answered Oct 03 '22 19:10

Jairo Martínez


  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.

like image 27
Abhay K. Avatar answered Oct 03 '22 19:10

Abhay K.


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>
like image 23
Gene Bo Avatar answered Oct 03 '22 19:10

Gene Bo


**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 **

like image 25
keepTrackOfYourStack Avatar answered Oct 03 '22 17:10

keepTrackOfYourStack


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.

like image 41
Greg Ennis Avatar answered Oct 03 '22 19:10

Greg Ennis


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

like image 33
Luis Avatar answered Oct 03 '22 18:10

Luis


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

like image 25
AgentP Avatar answered Oct 03 '22 19:10

AgentP


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

has a problem. instead use:

classpath 'com.google.gms:google-services:4.2.0'
like image 27
Avnish Nishad Avatar answered Oct 03 '22 17:10

Avnish Nishad


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
            }
        ]
]     
like image 28
nhoxbypass Avatar answered Oct 03 '22 17:10

nhoxbypass


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

like image 45
Noah Vo Avatar answered Oct 03 '22 19:10

Noah Vo