Android: Automatically Choose Debug/Release Maps 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 API Key in release build doesn't work

I had this same problem, it was super frustrating. What I ended up doing was taking the key I made using my release keystore and putting it in the google developers console. Then, added the following into the android manifest.

<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="KEY GOES HERE"/>

I'm sure you read the documentation on this, but make sure you follow the instructions for the release certificate to the dot.

https://developers.google.com/maps/documentation/android/signup

You could also follow the link that was generated for you in the google_maps_api.xml file. This automates the process of entering the key into the developer console. However, make sure you still add that meta data value into your manifest.

Android google maps release key?

The same way you get a "debug" key. There is no real difference, just as there is no real difference between a debug and a release certificate in Android (except that the debug certificate gets created automatically for you and resides in your Android settings folder).

Get the SHA-1 fingerprint for your Android release key and use it along with the proper package name (debug builds usually have a ".debug" attached, so make sure to omit that) to create a new Google Maps Key in the Google Developer Console.



Related Topics



Leave a reply



Submit