Secrets Gradle plugin

Stay organized with collections Save and categorize content based on your preferences.

Google strongly recommends that you not check an API key into your version control system. Instead, you should store it in the file, which is located in the root directory of your project and then use the Secrets Gradle Plugin for Android to read the API key.

The Secrets Gradle Plugin for Android reads secrets, including the API key, from a properties file not checked into a version control system. The plugin then exposes those properties as variables in the Gradle-generated BuildConfig class and in the Android manifest file.

For a complete example of using the Secrets Gradle Plugin for Android to access an API key, see Set up an Android Studio project.

Installation and usage

To install the Secrets Gradle Plugin for Android in your Google Maps project:

  1. In your top-level settings.gradle file, include the Gradle plugin portal, Google Maven repository, and Maven central repository under the pluginManagement block. The pluginManagement block must appear before any other statements in the script.
    pluginManagement {
        repositories {
  2. In Android Studio, open your project-level build.gradle file and add the following code to the dependencies element under buildscript.
    plugins {
        // ...
        id '' version '2.0.1' apply false
  3. Open your module-level build.gradle file and add the following code to the plugins element.
    id ''
  4. Save the file and sync your project with Gradle.
  5. Open the in your project level directory, and then add the following code. Replace YOUR_API_KEY with your API key.
  6. Save the file.
  7. In your AndroidManifest.xml file, go to and update the android:value attribute as follows:
        android:value="${MAPS_API_KEY}" />
  8. Optionally edit the properties of the plugin to specify a different secrets file or other properties. In Android Studio, open your project-level build.gradle file and edit the secrets property:

    secrets {
        // Optionally specify a different file name containing your secrets.
        // The plugin defaults to ""
        propertiesFileName = ""
        // A properties file containing default secret values. This file can be
        // checked in version control.
        defaultPropertiesFileName = ''
        // Configure which keys should be ignored by the plugin by providing regular expressions.
        // "sdk.dir" is ignored by default.
        ignoreList.add("keyToIgnore") // Ignore the key "keyToIgnore"
        ignoreList.add("sdk.*")       // Ignore all keys matching the regexp "sdk.*"

What's next