【问题标题】:How to specify multiple source folders in build.properties when using ant to build Android projects?使用ant构建Android项目时如何在build.properties中指定多个源文件夹?
【发布时间】:2011-03-15 10:29:05
【问题描述】:

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

下面的cmets来自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 中构建 - 我使用 ant 设置自动构建。

【问题讨论】:

  • 请说明您正在使用什么任务。 javac 任务不使用 source.dir 属性。
  • 具体针对ANDROID项目,根据SDK的android CLI工具生成的cmets,可以在build.properties中指定source.dir。我会更新上面的问题并粘贴到 cmets 中。

标签: android ant build directory


【解决方案1】:

您是否尝试使用冒号分隔路径?我的 build.properties 看起来像这样:

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

【讨论】:

【解决方案2】:

在我这里的(高度定制的)build.xml 中,它解决了许多其他问题,我最终不得不将编译目标拉入我的 XML 并在那里指定多个源路径。您也可以这样做,只需将新目标放在 build.xml 中设置任务的定义之上。请注意,Android SDK 中有多个文件浮动,看起来都像是您应该用来自定义的文件,其中一些似乎是错误的,或者至少不能与最新的工具一起正常工作(在tools/ant/main_rules.xml 似乎在我的 Windows SDK 中不起作用)。我相信您想要的是最新SDK中的platforms/[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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-16
    • 2011-03-11
    • 2011-06-26
    相关资源
    最近更新 更多