159

Since I upgraded the project with the latest version of google services and libraries (9.0.0), I have this strange issue :

Error build

Grade console :

:app:processDebugGoogleServices
Parsing json file: /Users/cyrilmorales/Documents/Projects/mobilemeans-punainenristi/app/google-services.json
:app:processDebugGoogleServices FAILED
Error:Execution failed for task ':app:processDebugGoogleServices'.
> Missing api_key/current_key object
Information:BUILD FAILED

build.gradle (root) :

dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0-alpha1'
    classpath 'com.google.gms:google-services:3.0.0'
}

build.gradle (app) :

dependencies {
    ....
    compile 'com.google.android.gms:play-services-analytics:9.0.0'
    compile 'com.google.android.gms:play-services-gcm:9.0.0'
    compile 'com.google.android.gms:play-services-maps:9.0.0'
    compile 'com.google.android.gms:play-services-location:9.0.0'
    ...
}
apply plugin: 'com.google.gms.google-services'

However, it works well with the play service libraries in 8.4.0 and google-services 2.1.0

Do you have any idea of the solution ?

Tim
  • 41,901
  • 18
  • 127
  • 145
palmsnipe
  • 1,703
  • 2
  • 10
  • 7

17 Answers17

163

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.

Charuක
  • 12,953
  • 5
  • 50
  • 88
Jozka Jozin
  • 2,350
  • 1
  • 16
  • 12
  • I already tried this morning, it doesn't fix the problem even if I noticed small changes with my old google-services.json and the new one. – palmsnipe May 19 '16 at 08:37
  • 1
    Newly is in conf file "api_key": [ { "current_key": XXX } ] – Jozka Jozin May 19 '16 at 08:45
  • 1
    Which API key should go there? – Marco Zanetti May 19 '16 at 10:12
  • From https://console.developers.google.com > Credentials and create API key for Android. – Jozka Jozin May 19 '16 at 10:20
  • Oh, I get it. I actually put in my build.gradle file one row in the release section: resValue "string", "google_maps_api_key", VALUE_OF_RELEASE_API_MAPS_KEY and another in the debug section: resValue "string", "google_maps_api_key", VALUE_OF_DEBUG_API_MAPS_KEY and a placeholder in the AndroidManifest: So it puts the right value once the app is launched. What should I put in the "api_key": [ { "current_key": XXX } ] field in google-services.json? – Marco Zanetti May 19 '16 at 10:47
  • I tried putting the release key and the debug one as well, doesn't work: "api_key": [{ "current_key": "ApemSyBll61Ij0Swz1mbGz4rZzxquSacbHIajir" }], – Marco Zanetti May 19 '16 at 10:56
  • 8
    You must enable Cloud Messaging even if you don't use it and generate a new json file. When you enable Cloud Messaging you get the API key need it for it. – Rafael Gutiérrez May 19 '16 at 17:46
  • @RafaelGutiérrez Tried this but did not get any value here ("api_key": []). Cloud messaging + Analytics is enabled. Must be something else. Maps? Any bug posted at Google for this? – Gober May 20 '16 at 07:41
  • In my case when I add this new service the key was automatically inserted in the file, and also, Google Api Console create a new credential called "Android key (auto created by Google Service)" with the same key. – Rafael Gutiérrez May 20 '16 at 07:54
  • 2
    I got the API key in the JSON file by enabling the Cloud Messaging API "api_key": [ { "current_key": "the_api_key" } ], but still doesn't work. I don't really know what's wrong with it. :-/ – Marco Zanetti May 20 '16 at 08:41
  • Do you have the new key in Google API Console? – Rafael Gutiérrez May 20 '16 at 08:48
  • Yes, I got the new Key for Cloud Messaging in the Google API console – Marco Zanetti May 20 '16 at 09:13
  • I too have same issue. Updated google-services classpath. And enabled GCM and added Server API key tat is generated in google-services.json file. I get the old error "Attribute "orientation" has already been defined". Could anybody help me ? – cgr May 20 '16 at 17:53
  • I've tried generating the json file again. Same error – Michael Obi May 21 '16 at 18:01
  • 1
    It does work now, I get notifications, but I also get 2 errors in my log: "FirebaseInstanceId: Failed to resolve target intent service, skipping classname enforcement" and "FirebaseInstanceId: Error while delivering the message: ServiceIntent not found." – andrew May 23 '16 at 07:44
  • I was able to create the new config with the api_key parameter, but the IDE is still complaining that it is missing api_key – code May 27 '16 at 08:13
  • For some reason simply regenerating the file (though it was a little different) didn't add the API key. But I added it manually and it worked. Thanks! – AXE May 31 '16 at 08:01
  • You may have to disable 'Google Cloud Messaging' first from here ( https://console.developers.google.com/apis/api/googlecloudmessaging/overview?project=_ ). Then generate the config file from here ( https://developers.google.com/cloud-messaging/android/client#get-config ). – Hejazi Jun 12 '16 at 13:06
  • 7
    Who knows what this api_key is for? It worked fine without it before... – Pavel Biryukov Jul 05 '16 at 12:43
  • @PavelBiryukov Were you able to find the use of API key? Is the the GCM API key or Google Maps or something else? – Shobhit Puri Jul 09 '16 at 16:02
  • It seems for FireBase messaging https://firebase.google.com/docs/reference/android/com/google/firebase/FirebaseOptions.Builder – Pavel Biryukov Jul 12 '16 at 07:28
  • it redirects to console in that FCM and in my app i need google plus login also so what can i do please help befor gplus is working coming its not working – Harsha Sep 28 '16 at 15:02
90

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

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

DiscDev
  • 38,652
  • 20
  • 117
  • 133
Ajax -the Max
  • 1,049
  • 9
  • 20
  • 1
    Just thought I'd add that the "api_key" value is inside the "client" value – Jan Jun 20 '16 at 16:37
  • 2
    @Ajax -the Max: This worked for me too. Could you be so kind as to explain why this works? – Pineda Dec 30 '16 at 17:36
  • 1
    this seems to best solution if utilising old GMS cloud messaging. New config file excludes GMS key instead adding Firebase. – GordonW Jul 20 '17 at 19:19
34

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

enter image description here

you can download google-services.json again.

enter image description here

Htoo Aung Hlaing
  • 2,173
  • 15
  • 26
  • 2
    yes i downloaded it again and it was bigger file the next time and this fix the issue for me – Hatem Badawi Dec 11 '16 at 07:58
  • 1
    I can confirm: I signed up for Firebase Analytics and it automatically downloaded a google-services.json containing no API key. Then i downloaded it manually like this and the API key was in the json. – chichilatte Jan 24 '17 at 13:26
  • What is the URL to get to this dashboard? – Sean Beach Apr 21 '17 at 19:29
9

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.

Elvis Oliveira
  • 941
  • 2
  • 15
  • 29
8

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.

1) choose an app

2: Close the popup! It hides...

Close the popup!

3: THE OPTION OF ADMOB!

the hidden option of admob

4: Of course, select and enable it!

enable it!

5: Now we can rightly generate configuration files!

generate configuration files

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

we made it!

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

TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
hata
  • 11,633
  • 6
  • 46
  • 69
  • 1
    thanks, I was able to get the new config, but the IDE is still complaining that it is missing api_key – code May 27 '16 at 08:10
  • A *bit* confusing... It is horrific!!! Kudos for your clear explanation. – Niels Jul 05 '16 at 14:16
7

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.

W4R10CK
  • 5,502
  • 2
  • 19
  • 30
Anubhav
  • 1,984
  • 22
  • 17
4

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.

Doge
  • 853
  • 11
  • 35
3

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

Phileo99
  • 5,581
  • 2
  • 46
  • 54
2

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

dx3906
  • 327
  • 1
  • 4
  • 12
2

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.

David Velasquez
  • 2,346
  • 1
  • 26
  • 46
2

enter image description here

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

enter image description here

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!

Pinkesh Darji
  • 1,041
  • 10
  • 23
2

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
Hexise
  • 1,520
  • 15
  • 20
1

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'
}
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
1

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" }]
Shakti
  • 1,581
  • 2
  • 20
  • 33
0

For firebase migrators:

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

Suau
  • 4,628
  • 22
  • 28
  • Thanks man, I went as per code lab instructions and did not add SHA1 key at first. Later I had to add as my ApiKey - CurrentKey was missing. Not sure if that was the case or not. But it solved my issue. – Rana Ranvijay Singh May 17 '18 at 06:05
0

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

Voora Tarun
  • 1,266
  • 1
  • 20
  • 38
0

add this into your google-service.json file . you will find it under app/google-service.json

"api_key": [ { "current_key": " your-google-api-key" }]