Kirit Vaghela Kirit Vaghela - 1 month ago 13
Android Question

Android: automatically choose debug/release Maps v2 api key?

I'm using Google Maps v2 API in my project. In Google Maps v2 the debug/release API key is defined in

AndroidManifest.xml
. I have seen the link but in that map key is defined in a xml layout file not in
AndroidManifest.xml
. So can I define both debug and release keys for my project in
AndroidManifest.xml
?

I want something like this in
AndroidManifest.xml
:

If debug mode:

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


If release mode:

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

Answer

I solved this issue using this steps:

In Google Developer API Console

  1. Click on Create New Android key...
  2. In cmd.exe/Terminal: keytool -list -v -keystore mystore.keystore
  3. Password: android
  4. Now enter SHA1 key;package name for debug and press enter
  5. Enter SHA1 key;package name for release
  6. Click on Create

Now use this API key your project

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