Android Ant构建在具有两个源文件夹的项目上

时间:2010-11-03 14:41:29

标签: android ant

我有一个带有链接源文件夹的项目。此项目依赖于另一个(远程服务)项目,因此 aidl文件和通过远程接口传递的类位于两个项目之间共享的common_src链接文件夹中。这个工作与Eclipse构建一样好(一个源文件,两个项目,一个项目中的更改反映在另一个项目中,就像它应该的那样)。

我现在想从命令行执行Ant构建。我设法使用SDK工具中的示例build.xml在所有目标上构建了一个单个src目录的项目。它会自动导入ant_rules_r3.xmlsource.dirout.dirbuild.properties中定义后,一切都相当轻松。

转向包含srccommon_src文件夹的项目,我无法构建它。首先,我将编译目标及其所依赖的所有内容剪切并粘贴到设置任务上方的build.xml中。我添加了元素common_src并将其定义为build.properties,并将下面显示的最后一行添加到-compile target(从ant_rules_r3.xml复制)到build xml:< / p>

  <src path="${source.absolute.dir}" />
  <src path="${gen.absolute.dir}" />
  <src path="${common_src}" /><!--ADDED-->

在构建过程中进一步发展 - 它可以在common_src中找到.java文件,但不能找到.aidl文件。毫不奇怪,我意识到,援助是一个单独的目标。然后我添加了

<src path="${common_src}" /> 

到build xml中的-aidl目标,但失败了:

BUILD FAILED
C:\dev\projects\Eclipse\AndroidWorkspace\MapProject\build.xml:77: aidl doesn't
 support the nested "src" element.

所以这让我很好并且真正陷入困境。 理想情况下,我只想修改build.properties文件以包含common_src并将其传递给ant_rules_r3.xml,但我想不出这样做的方法。如果有人能够建议如何做到,我将非常感激。

6 个答案:

答案 0 :(得分:16)

我遇到了类似的问题,但似乎已经通过build.properties文件中的以下设置解决了这个问题:

source.dir = src;../other_project/src

我使用相对路径将我的src链接到other_project,但您应该能够使用绝对路径。如果你这样做,你应该把它放在local.properties中。

注意:根据build.properties中的注释,如果我的SDK版本&lt; 2.0我会改用它:

source-folder = src;../other_project/src

答案 1 :(得分:6)

如果有任何兴趣,我想我会回答我现在已经解决的问题。

1)我在build.properties

中定义了common_src

2)添加了一行

<src path="${common_src}"

在设置上方的build.xml中的重写编译目标中(加上通过从ant_rules_r3.xml剪切/粘贴来覆盖它所依赖的所有目标) 3)添加了一个新的目标'aidl2',与build.xml中的'aidl'相同但是有一行

<source path="${common_src}"而不是

<source path="${source.absolute.dir}" .

Made aidl取决于aidl2。覆盖了援助所依赖的所有目标。

我还添加了以下行:

key.store=xxxxxxxxxxxxx
key.alias=xxxxxxxxxxxxx
key.store.password=xxxxxxxxxxxxx
key.alias.password=xxxxxxxxxxxxx

到build.xml,它自动输入密码。我最后添加了一个install_release目标来自动生成一个命令构建,恢复和安装过程。

答案 2 :(得分:6)

我无法发表评论,因为我没有足够的声誉但是如果添加源文件夹可以使用以前的答案,那么在构建jar时会失败:


compile:
    [javac] Compiling 463 source files to /home/xxx/documents/eclipse/xxx/deploy/xxx/bin/classes
    [javac] Note: Some input files use or override a deprecated API.
    [javac] Note: Recompile with -Xlint:deprecation for details.
    [javac] Note: Some input files use unchecked or unsafe operations.
    [javac] Note: Recompile with -Xlint:unchecked for details.
    [javac] Creating empty /home/xxx/documents/eclipse/xxx/deploy/xxx/bin/classes/fr/xxx/android/socialintegration/facebook/package-info.class
     [echo] Creating library output jar file...

BUILD FAILED
/home/xxx/applis/android/android-sdk-linux/tools/ant/build.xml:570: The following error occurred while executing this line:
/home/xxx/applis/android/android-sdk-linux/tools/ant/build.xml:680: The following error occurred while executing this line:
/home/xxx/applis/android/android-sdk-linux/tools/ant/build.xml:744: /home/xxx/documents/eclipse/xxx/deploy/xxx/src;../xxxdata/src does not exist.

故障部分位于jar的构建中,使用source.absolute.dir作为filset,对于ant无效。

但我暂时没有任何解决方法,我不明白为什么其他人设法让它工作...... (我也在使用sdk r20)

答案 3 :(得分:2)

;分隔的来源列表添加到ant.properties(不要忘记包含默认src):

source.dir=src-other;src

以上适用于Android SDK Tools Revision 20.0.3+(项目目标:Android 2.2 +,API级别:8+)。

答案 4 :(得分:0)

这是解决方案:

更新build.xml以获取多个source.dir

https://stackoverflow.com/a/14786100/2732600

答案 5 :(得分:0)

至少在构建工具的更高版本上,问题是放入此属性的值会传递到<property name="source.absolute.dirs" location="source.dirs"/>location属性不知道如何处理冒号/分号分隔的路径。

修复非常简单,只需使用:

source.absolute.dirs=src1:src2:src3

等,而不是:

source.dirs=src1:src2:src3
相关问题