How to use google-services.json and Google Maps API key?

Viewed 2610

An app uses Firebase and Google Maps Android SDK.

Firebase works fine by using the google-services.json file downloaded on the Firebase console.

However the Google Maps API key is provided in the AndroidManifest.xml file with:

<meta-data
   android:name="com.google.android.geo.API_KEY"
   android:value="${google_maps_key}" />

while the google maps key is provided in build.gradle according to build variant:

manifestPlaceholders.google_maps_key = "<REMOVED>";

The Google Maps feature works in debug build variant but it doesn't work in release. The APIs in the Google Cloud Console are enabled and the credentials are correct (SHA1 fingerprints, API restrictions). The Google Cloud console does not show any API requests for the release project.

The google-services.json contains an API key that I did not find anywhere in the Google Cloud console or Firebase ("api_key": [{ "current_key": <REMOVED> }]).

Is is possible that JSON file conflicts with the Google Maps API key?

1 Answers

You can use the following, note that google_api_key will be automatically generated with google-services.json if you use google-play gradle plugin (i.e. id("com.google.gms.google-services"))

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