I worked on a terrible incorrect integration of api keys in the process of building and managing source code by creating its property stored in local.properties . I had to add the following to build.xml :
<property name="mapviewxml" value="res/layout/mapview.xml" /> <target name="-pre-build"> <fail unless="mapsApiKey">You need to add mapsApiKey=... to local.properties</fail> <copy file="mapview.xml.tpl" tofile="${mapviewxml}" overwrite="true"> <filterchain> <replacetokens> <token key="apiKey" value="${mapsApiKey}"/> </replacetokens> </filterchain> </copy> </target>
Now, of course, I had to create mapview.xml.tpl in my root project (it cannot go to res/layout because it will break the build process):
<?xml version="1.0" encoding="utf-8"?> <com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mapview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="@apiKey@" />
During pre-compilation, the template is copied to the right place, and @apiKey @ is replaced with the real key. Unfortunately, I did not find a way to distinguish between debug and release assemblies at this stage, so for compilation for release, I just add apiKey for release to the ant parameters:
ant -DmapsApiKey=.... release
This approach integrates well with SCM (I do not need to verify the keys) and is acceptable with the build process.
ge0rg Dec 12 '10 at 9:57 2010-12-12 09:57
source share