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

发布于 2024-09-09 11:46:39 字数 1034 浏览 1 评论 0原文

显然,我可以使用 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 中构建 - 我使用 ant 设置自动构建。

Apparently, I can specify source folders using the source.dir property in build.properties - but what if I want to specify multiple source folders ?

The comments below are from the build.xml file generated by the Android SDK tools:

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

     -->

Note: I dont care about building in Eclipse - Im setting up automated builds using ant.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

⒈起吃苦の倖褔 2024-09-16 11:46:39

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

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

Did you try using colons to separate paths? My build.properties looks like this:

source.dir=src:src2:src3:src4:src5
戴着白色围巾的女孩 2024-09-16 11:46:39

在我这里的(高度定制的)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>

In the (heavily customized) build.xml I have here, that solves a bunch of other issues, I ended up having to just pull the compile target into my XML and specifying more than one source path there. You can do the same, just put the new target above the definition of the setup task in your build.xml. Note that there are multiple files floating around in the Android SDK that all look like the one you should be using to customize, and a couple of them appear to be wrong or at least don't work properly with the latest tools (the one in tools/ant/main_rules.xml doesn't seem to be working in my Windows SDK). I believe the one you want is in platforms/[platform-numer]/ant/ant_rules_r2.xml in the latest SDK. At any rate, the task looks like the task below, and you can just add another source directory to it pretty easily. I haven't tried separating with colons, like the other answer here, because as I said, our build.xml had to be customized in a number of ways. But I do know this will work.

<!-- 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文