Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Just finished coding an Android app and am preparing to release it to the Play Store. During development, I obtained a Google Maps API Key using my debug.keystore, and placed this key in my Manifest, like so:

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

However, I've now signed my app with my release certificate, and thus got a new API key from Google Maps. For testing purposes, is there a way to keep both the old (debug) and new (release) API key in my Manifest, with a switch that loads the proper one at run time? Ex:

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!

like image 488
giaset Avatar asked Feb 16 '23 18:02

giaset


1 Answers

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

On the API Console edit allowed apps and add SHA;package pairs, one pair per line.

like image 198
MaciejGórski Avatar answered Feb 27 '23 10:02

MaciejGórski