简体   繁体   English

Android库项目自定义Ant构建

[英]Android library project custom Ant build

I have a library project that serves as the backend for a number of other projects. 我有一个图书馆项目,可以作为许多其他项目的后端。 It does the web connection and parsing etc. Then I have other front end projects that build on this. 它进行网络连接和解析等。然后,我在此基础上开发了其他前端项目。 For development and server environments I wrote an ANT build script that replaces certain values in the code bases on the build type. 对于开发和服务器环境,我编写了一个ANT构建脚本,该脚本替换了基于构建类型的代码中的某些值。 So I have two targets buildDev and buildProd . 所以我有两个目标buildDevbuildProd

Is there a way for me to have the values set correctly while building the dependent (non-library projects). 在构建依赖项(非库项目)时,有没有办法让我正确设置值。 Eg if I do ant debug on the project it builds the backend with ant buildDev and if I do ant release it does it with ant buildProd . 例如,如果我在项目上进行ant debug ,它将使用ant buildDev构建后端,如果我进行ant release ,则将使用ant buildProd进行后端ant debug

I'm pretty sure that's not possible, so what are the alternatives. 我很确定这是不可能的,那么还有哪些选择。

For the curious, the custom builds just replaces a file that has static variables that are assigned different values based on the type of build. 出于好奇,自定义构建仅替换具有静态变量的文件,该文件根据构建的类型分配了不同的值。 Nothing too complex. 没什么复杂的。

In ant, there are a variety of different tasks that can be used to edit properties in a file. 在ant中,可以使用多种不同的任务来编辑文件中的属性。

I'm sure you're aware of property files, so if you use the documentation here: 我确定您知道属性文件,因此如果您在此处使用文档:

http://ant.apache.org/manual/index.html http://ant.apache.org/manual/index.html

It could probably help you. 它可能会帮助您。

If you set your variables in an ant-style property file, then for certain builds you could have separate files for separate builds, and then therefore have the variables set correctly. 如果您在ant样式的属性文件中设置变量,那么对于某些构建,您可以为单独的构建使用单独的文件,然后正确设置变量。

If you're talking about having variables set in your source, try the copy task: 如果您要在源中设置变量,请尝试复制任务:

http://ant.apache.org/manual/index.html http://ant.apache.org/manual/index.html

Filterchains on a copy task will allow you to replace certain lines of code out of a file. 复制任务上的过滤链将使您可以替换文件中的某些代码行。 So if you have a variable named server_ip or something like that, you can use a filterchain to change that value and re-copy that source file back into your tree. 因此,如果您有一个名为server_ip或类似名称的变量,则可以使用过滤链更改该值,然后将该源文件重新复制回您的树中。

I hope this answers your questions. 我希望这回答了你的问题。 If not, be gentle. 如果不是,请保持温柔。 I'm kinda new at answering stuff and I got slightly chewed out on an Android post haha. 我在回答问题上有点新手,在Android帖子上我被略微咀嚼了哈哈。

I found the solution. 我找到了解决方案。 The default Android Ant build.xml passes the release name to the child library project script while calling it. 默认的Android Ant build.xml在调用时将发布名称传递给子库项目脚本。 The following lines and the code that follows details it. 以下几行和后面的代码对其进行了详细说明。

<!-- figure out which target must be used to build the library projects.
If emma is enabled, then use 'instrument' otherwise, use 'debug' -->
<condition property="project.libraries.target" value="instrument" else="${build.target}">
    <istrue value="${build.is.instrumented}" />
</condition>

Then it's just a matter of having the same targets in all the interdependent projects. 然后,只需在所有相互依赖的项目中拥有相同的目标即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM