Android: Automatically Choose Debug/Release Maps V2 API Key

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

Using build.gradle

buildTypes {

debug {
buildConfigField("String", "map_api_key", "\"your debug map api key here\"")
}
release {
buildConfigField("String", "map_api_key", "\"your release map api key here\"")
}
}

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"/>

Android: automatically choose debug/release Maps api key?

There is a new way to determine is it a debug build or release one in SDK Tools, Revision 17. An excerpt from new features overview:

Builds now generate a class called BuildConfig containing a DEBUG constant that is automatically set according to your build type. You can check the (BuildConfig.DEBUG) constant in your code to run debug-only functions.

So now you can simply write something like this:

if (BuildConfig.DEBUG)
{
//Your debug code goes here
}
else
{
//Your release code goes here
}

UPDATE: I've encountered bug in ADT: sometimes BuildConfig.DEBUG is true after exporting application package. Description is here: http://code.google.com/p/android/issues/detail?id=27940

Android add separate google map api key for release and debug build modes

Just create same xml file in release folder.

You're default debug key is probably in file project_location/src/debug/res/values/some_file_name.xml.

You need to create same file in project_location/src/release/res/values/some_file_name.xml And put you'r release key there.

How to change google map api key from debug to release in android?

generate your hash using your sign apk. and than update your sha1 in google developer console.

Automatically change map key based on debug or release version

The best thing you can do it not to have to change it at all.

First of all, you can check in the API_KEY into your repository even if it is public. Nobody can use the key without having your debug or release keystore (and passwords).

Secondly, you can assign a single API key multiple SHA-1;package pairs in the Google APIs Console.

maps working with debug API key but not with release API key...?

See njzk2's comment:

use adb to install the apk on your device/emulator (adb install app.apk). Don't forget to uninstall the debug version first, otherwise the signature difference will prevent the installation

Google Maps Android V2 debug and release key

In the new API (Version 2) you can have the same key for multiple sha-1 fingerprints.

Can it be that you have configured in your APIs Console, the API key with both your debug and release keystore fingerprint like so:

Google APIs Console

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

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.



Related Topics



Leave a reply



Submit