如何在使用ant构buildAndroid项目时在build.properties中指定多个源文件夹?

显然,我可以使用build.properties中的source.dir属性指定源文件夹 – 但是如果我想指定多个源文件夹呢?

下面的评论来自Android SDK工具生成的build.xml文件:

<!-- The build.properties file can be created by you and is never touched by the 'android' tool. This is the place to change some of the default property values used by the Ant rules. Here are some properties you may want to change/update: application.package the name of your application package as defined in the manifest. Used by the 'uninstall' rule. source.dir the name of the source directory. Default is 'src'. out.dir the name of the output directory. Default is 'bin'. Properties related to the SDK location or the project target should be updated using the 'android' tool with the 'update' action. This file is an integral part of the build system for your application and should be checked in in Version Control Systems. --> 

注意:我不在乎在Eclipse中构build – 我使用ant来设置自动构build。

Solutions Collecting From Web of "如何在使用ant构buildAndroid项目时在build.properties中指定多个源文件夹?"

你尝试用冒号来分隔path吗? 我的build.properties如下所示:

 source.dir=src:src2:src3:src4:src5 

在这个(很大程度上是自定义的)build.xml中,我解决了一堆其他的问题,最后我不得不把这个编译目标放到我的XML中,并指定了多个源代码path。 你可以这样做,只要把新的目标放在你的build.xml中设置任务的定义之上即可。 请注意,Android SDK中存在多个文件,全都看起来像您应该用来自定义的文件,其中一些似乎是错误的,或者至less不能用最新的工具正常工作tools / ant / main_rules.xml似乎不能在我的Windows SDK中工作)。 我相信你想要的是在最新SDK中的platform / [platform-numer] /ant/ant_rules_r2.xml。 无论如何,任务看起来像下面的任务,你可以很容易地添加另一个源目录。 我没有尝试用冒号分隔,就像这里的其他答案,因为正如我所说,我们的build.xml必须以多种方式进行自定义。 但是我知道这会起作用。

 <!-- Compiles this project's .java files into .class files. --> <target name="compile" depends="-resource-src, -aidl" description="Compiles project's .java files into .class files"> <!-- If android rules are used for a test project, its classpath should include tested project's location --> <condition property="extensible.classpath" value="${tested.project.absolute.dir}/bin/classes" else="."> <isset property="tested.project.absolute.dir" /> </condition> <condition property="extensible.libs.classpath" value="${tested.project.absolute.dir}/libs" else="./libs"> <isset property="tested.project.absolute.dir" /> </condition> <javac encoding="ascii" target="1.5" debug="true" extdirs="" destdir="${out.classes.absolute.dir}" bootclasspathref="android.target.classpath" verbose="${verbose}" classpath="${extensible.classpath}" classpathref="android.libraries.jars"> <src path="${source.absolute.dir}" /> <src path="${gen.absolute.dir}" /> <src refid="android.libraries.src" /> <classpath> <fileset dir="${external.libs.absolute.dir}" includes="*.jar" /> <fileset dir="${extensible.libs.classpath}" includes="*.jar" /> </classpath> </javac> </target>