I want to attach different string resources files during android ant release and debug builds. I need this to have separate configuration for map api key, remote host etc
The XML resource files containing localized strings are placed in subfolders of the project's res folder.
A single string that can be referenced from the application or from other resource files (such as an XML layout). Note: A string is a simple resource that is referenced using the value provided in the name attribute (not the name of the XML file).
A string resource provides text strings for your application with optional text styling and formatting. There are three types of resources that can provide your application with strings: String. XML resource that provides a single string.
I use Eclipse for day to day debug builds, then Ant for release builds. I have debug and release versions of the file holding the Google Maps API key. I've modified the build.xml (I'm on SDK tools R15) to do some copying of the appropriate file before the build and afterwards. I've changed the -pre-build and release targets like so:
<target name="-pre-build">
<echo message="In pre build-----------------------------------" />
<echo message="build target ${build.target}" />
<if condition="${build.is.packaging.debug}">
<then>
<echo>Copying debug api key************************************</echo>
<copy file="${layout.dir}/googlemapdebug.xml" tofile="${layout.dir}/googlemap.xml" overwrite="true" />
</then>
<else>
<echo>Copying RELEASE api key************************************</echo>
<copy file="${layout.dir}/googlemaprelease.xml" tofile="${layout.dir}/googlemap.xml" overwrite="true" />
</else>
</if>
</target>
<target name="release"
depends="clean, -set-release-mode, -release-obfuscation-check, -package, -release-prompt-for-password, -release-nosign"
............. LINES OMITTED
.............
<!-- Zip aligns the APK -->
<zipalign-helper in.package="${out.unaligned.file}"
out.package="${out.final.file}" />
<echo>Release Package: ${out.final.file}</echo>
<echo>Always copy DEBUG MAPS API file back for Eclipse **********************</echo>
<copy file="${layout.dir}/googlemapdebug.xml" tofile="${layout.dir}/googlemap.xml" overwrite="true" />
</sequential>
</do-only-if-not-library>
<record-build-info />
</target>
I define layout.dir in the ant.properties (new name for build.properties post SDK Tools 14) file:
projectname=MyProject
workspace.dir=/dev/projects/EclipseIndigo/AndroidWorkTwo
base.dir=${workspace.dir}/${projectname}
layout.dir=${base.dir}/res/layout
You could adapt this to suit your needs, assuming you don't have too many files to swap in and out. I guess you could add a property for the directory holding your strings.xml
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With