157
votes

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 ?

17
I am using maps and I have api_key defined in AndroidManifest.xml file. Have you got api_key there? Something like that <meta-data android:name="com.google.android.geo.API_KEY" android:value="AIzaSdfdfdfdfdfdfdfdfdRVxThQsNaqY" />Grzegorz Bielański
Yes, I have it. The Manifest is well configured, it always worked .. until now.palmsnipe

17 Answers

162
votes

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.

89
votes

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

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

34
votes

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

9
votes

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.

8
votes

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

7
votes

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.

4
votes

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.

3
votes

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

2
votes

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

2
votes

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.

2
votes

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!

2
votes

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

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

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" }]
0
votes

For firebase migrators:

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

0
votes

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

0
votes

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" }]