Tuesday, March 9, 2010

Google Maps API Keys on Android

For any Android devices with the Google APIs add-on installed, there is a very convenient way to integrate Google Maps with your application: the MapView. Using this view allows an app developer to create custom interfaces using other components rather than just launching the built-in Google Maps application via an intent. Needless to say, it is a very powerful feature that can be added with minimal effort.

To use this feature, however, one has to register for an application key from Google. Normally, this would be a reasonable request. In this day and age of mash-ups and public APIs, registering for keys is the status quo. What differs here is that the public-key fingerprint of certificate used to sign the application must be submitted in order to get the key. The key is generated using this fingerprint as a seed for the key generation and will only work when deployed in an app signed by that same certificate. At first glance, this too is perfectly reasonable. The annoyance comes when one realizes that a different certificate is used to sign your application for development/debugging than is used for production release (which is the default behavior for the Android Development Toolkit). If 2 different certificates are used, two different keys are needed and, since the key is embedded in the layout file that uses the MapView, one must have two different build configurations - one that uses the debug key and another that uses the release key in the layout file.

This leaves one with little recourse but to either use the production certificate during development/debug, manually change the key in the layout file before doing a build, or use a tool like ANT or Maven to swap in the right version of the file at build time based on a profile. I was planing on configuring Maven for this project using an open-source Maven ADK plug-in at some point anyway, looks like I have another reason to do so.

No comments:

Post a Comment