Missing api_key/current key with Google Services 3.0.0

我是研究僧i 提交于 2019-11-27 10:37:40
Jozka Jozin

Generate new config file (google-services.json) from: https://developers.google.com/cloud-messaging/android/client#get-config

Newly config file with "api_key": [ { "current_key": XXX } ] in client section

Update: or manually enabled service in developer console and generate key.

Ajax -the Max

Adding empty current key value in google-services.json file solved this problem for me

"api_key": [{ "current_key": "" }]

Yes, as for the first time using with Firebase, i face like that.Click on your app menu and click "Manage".

you can download google-services.json again.

For everyone that have this issue, for now, you'll need to add any service to your app at https://developers.google.com/cloud-messaging/android/client#get-config

In my case I have added admob (already have analytics and gcm) and then the file was generated with api_key.

I think's it's a bug and will be soon fixed, until that, do it.

hata

Although Jozka Jozin's accepted answer and its comments, Cloud Messaging is neither related nor required.

Nevertheless, re-generating google-services.json is the key to solution (so I voted him). Below is what I did:

As you know you can generate the config file for Analytics from the Google Developers Guide.

1: Choose your app.

2: Close the popup! It hides...

3: THE OPTION OF ADMOB!

4: Of course, select and enable it!

5: Now we can rightly generate configuration files!

6: We made it! This time, the configuration file should include the api_key appropriately.

Conclusion: The UI of the interactive generation tool is a bit confusing...

Anubhav

You can download the google-services.json file again.

Steps to download:

1). Click on the top menu in your app in the Firebase Console.

2). Click on manage.

3). You will find Download the latest config file option, download and replace the google-services.json file in your application.

First in your JSON file

Replace

"api_key": []

with

"api_key": [{ "current_key": "" }]

Then the gradle build will be successful but when you run your application you may get errors like the following..

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/LICENSE
    File1: C:\Users\bucky\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-core\2.2.2\d20be6a5ddd6f8cfd36ebf6dea329873a1c41f1b\jackson-core-2.2.2.jar
    File2: C:\Users\bucky\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-databind\2.2.2\3c8f6018eaa72d43b261181e801e6f8676c16ef6\jackson-databind-2.2.2.jar
    File3: C:\Users\bucky\.gradle\caches\modules-2\files-2.1\com.fasterxml.jackson.core\jackson-annotations\2.2.2\285cb9c666f0f0f3dd8a1be04e1f457eb7b15113\jackson-annotations-2.2.2.jar

To fix this issue you can add the following to your app.gradle file.. It worked for me.

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

Edit: It showed me some error later while building the apk file. So I had to download the json file again. After 2 trial I got the json file with a valid api key.

If you are not using Firebase, the correct link to generate the google-services.json config file is actually found here.

regenerate google-services.json at https://developers.google.com/cloud-messaging/android/client#get-config,one important thing is that you must enable Cloud Messaging in "Choose services" step ,open the new google-services.json file you will see words like

    "api_key": [
     {
       "current_key": "xxxxxxxxxxx"
     }"

without this words or without value of current_key is not the right file

I was able to solve this problem with these steps that are not answered here. This answer is NOT enabling Cloud Messaging, it is only retrieving its server key.

So first, go to Firebase Console, and then go to Project Settings, and then click on the tab "Cloud Messaging". Look where it says "server key" and if there is no long key displaying (not the "Sender ID" number) click "Regenerate Key" and a long key should now show. Copy that key and place it in your google-services.json file at: "api_key": [ {"current_key" : "key goes here"} ].

This method helped me while none of the others were working, so hopefully this helps someone.

Click on Overview -> Gear icon -> Project settings.

Go to Download latest config and Click on google-service.json button to download file and save it to app folder and Compile again. Enjoy!

You need to add SHA certificate fingerprints to your project and then download the google-services.jason file again, which should contain "api_key": [{ "current_key": "xxxxxx" }] automatically.

You can view following page to see how to generate the fingerprints:

https://developers.google.com/android/guides/client-auth

On windows, just execute following command, and use android as password for debug purpose:

keytool -exportcert -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

Using Firebase

GoogleServices'. > Missing api_key/current_key object

I got this error after updating an existing project to the new Firebase Services. The generated google-service.json file downloaded from the firebase project settings page did not include the api_key needed.

From the other answers here it looks like Google/Firebase Cloud Messaging (GCM/FCM) needs to be added for this api_key to be included in the google-service.json file.

So I added a dependencies on the firebase FCM before downloading the file again, and this time the key was included.

Include FCM (GCM)

dependencies {
     compile 'com.google.firebase:firebase-messaging:9.0.0'
}

If you don't want to reconfigure and download the google-services.json file then you can fetch the api key directly from firebase console. Just go to

Overview > Add another App > Web

You will get configuration for your database which will contain apiKey. Just copy that value and place it in the current_key value denoted by XXX below

"api_key": [{ "current_key": "XXX" }]

For firebase migrators:

make sure you have added at least one Fingerprint in your project settings and re-download the google-services.json file

If you are using firebaes, you have to copy serverKey from the firebase to the google-services.json

 "api_key": [{ "current_key": "SERVER_KEY"}

To get the server Key, Goto ProjectOverview> Project Settings > CloudMessaging > Copy OR generate and copy serverKey..

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