# Using Build Types with the Google Services Gradle Plugin

DevFeed: [Using Build Types with the Google Services Gradle Plugin](<https://devfeed.tech/articles/using-build-types-with-the-google-services-gradle-plugin-25105.md>)

Original publisher: [Read original article](<http://michaelevans.org/blog/2016/03/31/using-build-types-with-the-google-services-gradle-plugin/>)

Author: Michael Evans

Published: 2016-04-01T01:11:55Z

Content type: tutorial

Language: en

Sources: [Gadget Habit](<https://devfeed.tech/sources/gadget-habit.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Android](<https://devfeed.tech/topics/android.md>), [Google](<https://devfeed.tech/topics/google.md>), [Groovy](<https://devfeed.tech/topics/groovy.md>), [JSON](<https://devfeed.tech/topics/json.md>), [API keys](<https://devfeed.tech/topics/api-keys.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [api-keys](<https://devfeed.tech/tags/api-keys.md>), [code](<https://devfeed.tech/tags/code.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [development](<https://devfeed.tech/tags/development.md>), [google](<https://devfeed.tech/tags/google.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [gradle-plugin](<https://devfeed.tech/tags/gradle-plugin.md>), [groovy](<https://devfeed.tech/tags/groovy.md>), [json](<https://devfeed.tech/tags/json.md>)

## AI overview

This tutorial explains how to use different Google Services configuration files for Android debug and release builds when the Google Services Gradle plugin supports build flavors but not build types. It presents a Groovy and Gradle task-based workaround that copies the appropriate JSON file into the app module before the Google Services processing task runs.

## Source excerpt

If you want to integrate your Android app with most of Google Play Services nowadays, you'll find that you are instructed to set up the Google Services Gradle plugin to handle configuring dependencies. The plugin allows you to drop a JSON file into your project, and then the plugin will do a bunch of the configuration for your project, such as handling the API keys. This is all well and good--unless you're like me (and countless others) and want to use a different configuration for your debug and release builds. This would be useful, as an example, if you use Google Play Services for GCM and would like to have development builds recieve pushes from non-production systems. It seems that the plugin is configured in such a way that it supports build flavors, but it does not yet support build types. However, with a little Gradle magic, we can hack that support in. Disclaimer: This approach worked for me--but as with any hack, it is subject to break. So how can we go about doing this? We want to put the debug JSON file into the root of our app module during debug builds and use the release one for release builds. If you don't do that, or if you attempt to put it in app/debug and app/release, you'll get an error that says File google-services.json is missing from module root folder. The Google Services Plugin cannot function without it. This error is thrown by a task named process{VariantName}GoogleServices. What we could do to solve this is swap the file in before that task is run! Using a little Groovy magic, I came up with this: 1 2 3 4 5 6 7 8 9 10 android.applicationVariants.all { variant -> def hackTask = task("hackGps${variant.name.capitalize()}") << { copy { from rootProject.file("config/${variant.buildType.name}/google-services.json") into "${projectDir}" } } def googleTask = tasks.findByName("process${variant.name.capitalize()}GoogleServices") googleTask.dependsOn hackTask } For each one of your variants, this code will create a new task - hackGps{VariantName}, wh