Android Google Maps v2 - Debug key vs Release key

Different Google Map API keys for debug build and release build can be defined in build.gradle:

...
android {
    ...
    buildTypes {
       debug {
           resValue "string", "google_maps_api_key", "<debug_key>"
           ...
       }
       release {
           resValue "string", "google_maps_api_key", "<release_key>"
           ...
       }
    }
}

Just replace <debug_key> and <release_key> with your actual keys.

And refer to this resource value in AndroidManifest.xml:

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

This solution is also described in the following Stack Overflow question:

Manage Google Maps API Key with Gradle in Android Studio


With version 2 API's you can use the same key for release and debug. In your google api's console edit your allowed android apps and on each line put your debug/release key, and then your app name. You can use multiple lines, then it will work with both keys.