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

Just finished coding an Android application and is ready to release it in the Play Store. During development, I got the Google Maps API key using my debug.keystore and put this key in my manifest, for example:

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

However, now I signed my application with my release certificate and thus received a new API key from Google Maps. For testing purposes, is there a way to save both the old (debug) and the new (release) API key in my manifest using a switch that loads the corresponding file at runtime? 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" /> } 

Hooray!

+4
source share
2 answers

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

In the API console, allowed applications are edited and SHA pairs are added; packets, one pair per line.

+8
source
  <!-- RELEASE key --> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/release_map_key" /> <!-- DEBUG key --> <meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="@string/debug_map_key" /> 

You add a few api keys to the manifest as shown above. But you can use the same api key for debugging and release.

0
source

Source: https://habr.com/ru/post/1493723/


All Articles