使用Ant进行Android自定义构建

xbe*_*eta 10 ant android build

运行时会自动生成这4个文件(build.xml,local.properties,projects.properties,proguard.cfg):

android更新项目--name TestApp --target 10 -p.

更新了project.properties

更新了local.properties

添加了文件./build.xml

更新文件./proguard.cfg

但我希望"auto-gen"build.xml也包含以下"预编译"代码,有没有办法做到这一点?是否有一些"包含"文件或"模板"文件可以包括?

  <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>
Run Code Online (Sandbox Code Playgroud)

ssc*_*rth 13

该工具build.xml生成的as android(至少在使用Android SDK r20时)包含以下代码:

<!--
    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" />
Run Code Online (Sandbox Code Playgroud)

因此,我创建其他目标或自定义现有目标的方法是custom_rules.xml使用这些新目标创建文件.请注意,在我的测试中,目标需要嵌套在<project>标记中,因此只需将生成的前两行复制build.xmlcustom_rules.xml,最后不要忘记结束</project>标记.由于custom_rules.xml不会被android update您的更改覆盖,因此可以持续检查您的SCM工具.