使用 Ant 的 Android 自定义构建 [英] Android custom build using Ant
问题描述
运行时自动生成这 4 个文件(build.xml、local.properties、projects.properties、proguard.cfg):
These 4 files (build.xml, local.properties, projects.properties, proguard.cfg) are auto-generated when running:
android update project --name TestApp --target 10 -p .
android update project --name TestApp --target 10 -p .
更新了 project.properties
Updated project.properties
更新了 local.properties
Updated local.properties
添加文件./build.xml
Added file ./build.xml
更新文件 ./proguard.cfg
Updated file ./proguard.cfg
但我想要自动生成"build.xml 还包括以下预编译"代码也是如此,有没有办法做到这一点?是否有一些包含"?文件或模板"可以包含那个的文件?
But I want the "auto-gen" build.xml to also include the following "pre-compile" code as well, is there a way to do that? Is there some "include" file or "template" file which can include that?
<target name="config">
<property name="config-target-path" value="${source.dir}/com/androidengineer/antbuild"/>
<!-- Copy the configuration file, replacing tokens in the file. -->
<copy file="config/Config.java" todir="${config-target-path}"
overwrite="true" encoding="utf-8">
<filterset>
<filter token="CONFIG.LOGGING" value="${config.logging}"/>
</filterset>
</copy>
</target>
推荐答案
android
工具生成的 build.xml
(至少在使用 Android SDK r20 时)包含这段代码:
The build.xml
as generated by the android
tool (at least when using Android SDK r20) contains this piece of code:
<!--
Import per project custom build rules if present at the root of the project.
This is the place to put custom intermediary targets such as:
-pre-build
-pre-compile
-post-compile (This is typically used for code obfuscation.
Compiled code location: ${out.classes.absolute.dir}
If this is not done in place, override ${out.dex.input.absolute.dir})
-post-package
-post-build
-pre-clean
-->
<import file="custom_rules.xml" optional="true" />
因此,我为创建其他目标或自定义现有目标所做的工作是使用这些新目标创建一个 custom_rules.xml
文件.请注意,在我的测试中,目标需要嵌套在
标记中,因此只需将生成的 build.xml
的前两行复制到 custom_rules.xml
,并且不要忘记结尾的 </project>
标记.由于 custom_rules.xml
不会被 android update
覆盖,因此您的更改将是持久的,并且可以检查到您选择的 SCM 工具中.
So what I do to create additional targets or customize existing targets is to create a custom_rules.xml
file with these new targets. Note that in my tests the targets needed to be nested in a <project>
tag, so simply copy the first two lines of your generated build.xml
to custom_rules.xml
, and don't forget about the closing </project>
tag in the end. As custom_rules.xml
will not be overwritten by android update
your changes will be persistent and can be checked into your SCM tool of choice.
这篇关于使用 Ant 的 Android 自定义构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!