Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing api_key/current key with Google Services 3.0.0 and Maps API key in build.gradle

my issue is quite similar to Missing api_key/current key with Google Services 3.0.0 but with a further level of complexity.

I updated my app this morning to com.google.gms:google-services:3.0.0 and all the play-services 9.0.0 dependencies

compile 'com.google.android.gms:play-services-analytics:9.0.0' compile 'com.google.android.gms:play-services-ads:9.0.0' compile 'com.google.android.gms:play-services-identity:9.0.0' compile 'com.google.android.gms:play-services-gcm:9.0.0' 

Now I get the infamous error

Error:Execution failed for task ':hotelsclick:processDebugGoogleServices'. > Missing api_key/current_key object

This seems to be due to a missing API key in the google-services.json file (so I was told). I got a new API key from https://developers.google.com/cloud-messaging/android/client#get-config and found the following field in it.

  "api_key": [], 

I guess I should put my Google Maps API key in there, but here it comes the double issue I'm experiencing:

1- if I try and put the key inside that field, it doesn't work. I tried with both

  "api_key": [{ "current_key": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-AE" }], 

and

  "api_key": ["XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX-AE"], 

the error remains the same.

2- I've been using gradle in order to use dynamic building. I put the following in my module build.gradle:

buildTypes {     release {         minifyEnabled true         shrinkResources true         debuggable false         resValue "string", "google_maps_api_key", "ABCDEFGHILMNO... my maps release API key"         proguardFiles getDefaultProguardFile('proguard-android.txt'),                 'proguard-rules.pro'         zipAlignEnabled true     }     debug {         resValue "string", "google_maps_api_key", "ZNTMRNCDNR... my google maps debug API key"         debuggable true         proguardFiles getDefaultProguardFile('proguard-android.txt'),                 'proguard-rules.pro'     } } 

In the Androidmanifest.xml file I have

    <meta-data         android:name="com.google.android.geo.API_KEY"         android:value="@string/google_maps_api_key" /> 

Now, it's always been working until I updated to Google Services 3.0.0, I don't get why it doesn't work now. Shouldn't it grab the right API key from the compiled build.gradle file and put it in the manifest?

So my double question is: why doesn't the dynamic API key fetching work anymore? And how can I fix this?

Thank you

like image 660
Marco Zanetti Avatar asked May 19 '16 13:05

Marco Zanetti


People also ask

Where do I get Google Map API key?

Go to the Google Maps Platform > Credentials page. On the Credentials page, click Create credentials > API key. The API key created dialog displays your newly created API key.


1 Answers

Have you tried putting an empty "current_key" as follows:

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

See how that goes.

EDIT: You should replace "api_key": [] (located in "client") with "api_key": [{ "current_key": "" }]

like image 180
Nitrodbz Avatar answered Sep 17 '22 21:09

Nitrodbz