Reputation: 4965
My Android manifest uses different values when debugging and when releasing.
What's the easiest way to differentiate a value for each build type?
When debug:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-lovely-debug-api-key" />
When release:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="my-lovely-release-api-key" />
tia.
Upvotes: 10
Views: 3306
Reputation: 6289
Note that if you are using default Eclipse builds it probably uses a specially configured 'Ant' module within eclipse. You can check on the degree of Eclipse/Ant coordination by checking 'Window/Preferences/Ant' section in eclipse/Prefs....
One solution is to make more explicit, the collaboration of Eclipse/Ant so that a 'build.xml' file is part of your project ( project level build file rather than the default file copied in at build time from the $SDK/ROOT folder ).
see here and read the comments at bottom here to get better idea of how a project level 'build.xml' file is used.
Once you've digested that , the solution below will make more sense...
--Solution--
Modify the Release and the Debug sections of you 'build.xml' file as follows:
<!-- **************** Debug specific targets *************** -->
...
<target name="-set-debug-mode" depends="-setup">
...
<!-- API modify belo for build-typ -->
<copy file="config/strings.xml" todir="res/values">
<filterset>
<filter token="CONFIG.API" value="${config.db.api}"/>
<filter token="CONFIG.REST" value="${config.db.rest}"/>
</filterset>
</copy>
...
<!-- *************** Release specific targets ************** -->
...
<target name="-set-release-mode" depends="-set-mode-check">
...
<!-- API modify belo for build-typ -->
<copy file="config/strings.xml" todir="res/values">
<filterset>
<filter token="CONFIG.API" value="${config.db.api.prod}"/>
<filter token="CONFIG.REST" value="${config.db.rest.prod}"/>
</filterset>
</copy>
And in the 'ant.properties' file in your root folder, put the property values for the API keys and whatever...
# API condition builds dev|prod in DB @parse.com
config.db.api=some_key_val
config.db.rest=some_k2_val
config.db.api.prod=some_k3_val
config.db.rest.prod=some_k4_val
And tie it together in a resource xml that is the target of the 'copy' commands in the build...
'config/strings.xml'
<string name="default_value_parse_key_appId">@CONFIG.API@</string>
<string name="default_value_parse_key_rest">@CONFIG.REST@</string>
Upvotes: 1