Java – Switch between Google Maps Android API v2 DEBUG and RELEASE API Key

Switch between Google Maps Android API v2 DEBUG and RELEASE API Key… here is a solution to the problem.

Switch between Google Maps Android API v2 DEBUG and RELEASE API Key

Just finished coding your Android app and are preparing to publish it to the Play Store. During development, I used my debug.keystore to get a Google Maps API key and put this key in my list, like this:

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

However, I have now signed my application with my publishing certificate, so I got a new API key from Google map. Is there a way to keep both the old (debug) and new (release) API keys in my list for testing purposes, and load the correct switch at runtime? For example:

if (debug) {
<meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="DEBUG_API_KEY" />
}

else if (release) {
<meta-data
  android:name="com.google.android.maps.v2.API_KEY"
  android:value="RELEASE_API_KEY" />
}

Cheers!

Solution

You can use the same key for multiple signing keys or even multiple applications.

Edit the allowed apps and add SHAs on the API console; Pack pairs, one pair per line.

Related Problems and Solutions