使用Ant Android的自定义生成 [英] Android custom build using Ant

查看:88
本文介绍了使用Ant Android的自定义生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行时,

这些4个文件(build.xml文件,local.properties,projects.properties,proguard.cfg)是自动生成的:

  

Android的更新项目--name TestApp --target 10 -p。

     

更新project.properties

     

更新local.properties

     

补充文件./build.xml

     

更新文件./proguard.cfg

不过,我想自动根build.xml文件还包括下面的pre-编译code还有,有没有办法做到这一点?有一些包括文件或模板文件,该文件可以包含?

 <目标名称=配置>

  <属性名=配置目标路径值=$ {source.dir} / COM / androidengineer / antbuild/>

  <! - 复制配置文件,在文件中替换标记。 - >
  <拷贝文件=配置/ Config.javatodir =$ {配置目标路径}
        覆盖=真正的编码=UTF-8>
   < filterset>
    <过滤器标记=CONFIG.LOGGING值=$ {config.logging}/>
   < / filterset>
  < /复制和GT;

 < /目标和GT;
 

解决方案

的build.xml 机器人工具(至少采用了Android SDK R20时)包含了这片code:

 <! - 
    每个项目的导入自定义生成规则,如果present在项目的根目录。
    这是把自定义的中介目标,如地方:
         -  pre-构建
         -  pre-编译
        -post编译(这通常用于code混淆。
                       编译code位置:$ {out.classes.absolute.dir}
                       如果这不到位完成的,覆盖$ {out.dex.input.absolute.dir})
        -post包
        -post建造
         -  pre-干净
 - >
<导入文件=custom_rules.xml可选=真/>
 

所以,我做什么,以创造更多的目标或定制现有的目标是创建一个 custom_rules.xml 文件与这些新的目标。请注意,在我的测试中被嵌套在&LT所需要的目标;项目> 标记,这样简单地复制前两行的生成构建。 XML custom_rules.xml ,也不要忘了关闭< /项目> 标签到底。由于 custom_rules.xml 将不会被 Android的更新将覆盖的变化将是持久的,可以放在你的SCM工具的选择。

These 4 files (build.xml, local.properties, projects.properties, proguard.cfg) are auto-generated when running:

android update project --name TestApp --target 10 -p .

Updated project.properties

Updated local.properties

Added file ./build.xml

Updated file ./proguard.cfg

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>

解决方案

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" />

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屋!

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