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).
4 Answers
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"

- 1
- 1

- 5,345
- 35
- 38
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.

- 43,056
- 28
- 105
- 132
-
This seems like the best approach - do you have any articles or examples? Setting up something like this and having it work with your existing IDE seems to be rather under-documented and I'm not experienced with Ant. – David Snabel-Caunt Mar 07 '12 at 15:48
-
I was actually thinking about writing up a blog post about our build setup, since it has grown quite complex and since we probably solve many problems others would have as well (dealing with a diverse set of dependencies such as upstream projects, JARs, and Android library projects, byte code injection for analytics, ProGuard for byte code optimization, automatically splitting up the build into configuration specific APKs for publishing etc. pp.). We use Maven for all that, although I intend to port everything over to Gradle again at some point (too unstable at the moment). – mxk Mar 07 '12 at 16:23
-
That being said, I actually don't have a lot of experience with Maven, and some things we do are not very Maven-ish I think. For instance, we reach out to a Groovy based build helper using GMaven to write and copy files instead of dealing with the more convoluted maven-resources-plugin. – mxk Mar 07 '12 at 16:25
You can pass the API Key to the MapView constructor if you want to set it programmatically.

- 3,509
- 1
- 20
- 26
-
The important point was not setting it, but setting it based on development environment. – gsgx Jan 03 '12 at 17:27