如何在 android ant 发布和调试版本期间附加不同的字符串资源文件? [英] How can I attach different string resource files during android ant release and debug builds?

查看:13
本文介绍了如何在 android ant 发布和调试版本期间附加不同的字符串资源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 android ant 发布和调试版本期间附加不同的字符串资源文件.我需要这个来为地图 api 密钥、远程主机等进行单独的配置

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

推荐答案

我使用 Eclipse 进行日常调试构建,然后使用 Ant 进行发布构建.我有包含 Google Maps API 密钥的文件的调试和发布版本.我已经修改了 build.xml(我使用的是 SDK 工具 R15),以便在构建之前和之后对适当的文件进行一些复制.我已经像这样更改了 -pre-build 和 release 目标:

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>

我在 ant.properties(SDK 工具 14 后 build.properties 的新名称)文件中定义了 layout.dir:

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

您可以调整它以满足您的需求,假设您没有太多文件需要换入和换出.我想您可以为保存 strings.xml 的目录添加一个属性

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

这篇关于如何在 android ant 发布和调试版本期间附加不同的字符串资源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆