gsgx
gsgx

Reputation: 12249

Changing Maps API Key based on development environment

I work in two different environments for developing an android application, and I have a different Maps API key for each SDK. I haven't tried copying one debug.keystore file to the other location, but I'd prefer if there was a way to selectively replace the key in a file based on the development environment. The key is used in an XML file (although there should be a way to set it programmatically).

Upvotes: 0

Views: 2111

Answers (4)

userM1433372
userM1433372

Reputation: 5497

You can register multiple certificates with on Maps key so you no longer have to use multiple keys. See https://stackoverflow.com/a/13881624/1433372

"One SHA1 certificate fingerprint and package name (separated by a semicolon) per line. Example: 45:B5:E4:6F:36:AD:0A:98:94:B4:02:66:2B:12:17:F2:56:26:A0:E0;com.example 45:B6:E4:6F:36:AD:1A:98:94:B4:02:66:2B:12:17:F1:56:26:A0:E0;com.example"

Upvotes: 3

mxk
mxk

Reputation: 43524

Here's what we do:

We keep the Maps key in a file called assets/environment.properties. By default, it contains the development key. At runtime during app startup we all values from that file into a hash, and construct our map views manually from the key in that file (you can pass the API key to the MapView constructor).

Whenever we release a new version, our build system copies a different template file to environment.properties, one that contains the production key. This step will be reversed once the app is built by discarding the change using the version control system (we use Git). It's all automatic.

This has worked very well for us so far.

Upvotes: 2

alosdev
alosdev

Reputation: 394

You can use property replacers in ant or if you are using maven the same there.

Upvotes: 1

Karthik
Karthik

Reputation: 3529

You can pass the API Key to the MapView constructor if you want to set it programmatically.

Upvotes: 0

Related Questions