Cannot resolve symbol default_web_client_id in Firebase's Android Codelab

前端 未结 19 1350
说谎
说谎 2021-02-01 05:18

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_cl

相关标签:
19条回答
  • 2021-02-01 06:11

    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

    0 讨论(0)
  • 2021-02-01 06:11

    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
                }
            ]
    ]     
    
    0 讨论(0)
  • 2021-02-01 06:16

    in my case I forgot to add

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

    to the plugin of build.gradle(:app)

    0 讨论(0)
  • 2021-02-01 06:21
    classpath 'com.google.gms:google-services:4.1.0'
    

    has a problem. instead use:

    classpath 'com.google.gms:google-services:4.2.0'
    
    0 讨论(0)
  • 2021-02-01 06:22

    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.

    0 讨论(0)
  • 2021-02-01 06:25

    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>
    
    0 讨论(0)
提交回复
热议问题