简体   繁体   中英

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. So I have two targets buildDev and buildProd .

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 .

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.

I'm sure you're aware of property files, so if you use the documentation here:

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.

If you're talking about having variables set in your source, try the copy task:

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.

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.

I found the solution. The default Android Ant build.xml passes the release name to the child library project script while calling it. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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