我使用ant工具构建android库项目,我需要指定多个源目录 .
我试图通过在ant.properties文件中添加这些行来指定多个源目录
source.dir=src:src2
source.dir=src;src2
但无法在两种情况下构建,在这两种情况下都生成了 .class ,但在创建jar文件时我收到此错误
BUILD FAILED
C:\Program Files\Android\android-sdk\tools\ant\build.xml:681: The following error occurred while executing this line:
C:\Program Files\Android\android-sdk\tools\ant\build.xml:749:
C:\workarea\Android\Packages\test\src;src2 does not exist.
任何人都可以告诉我如何在 ant.properties 中指定 multiple source directory 来构建 Android library projects ?
4 回答
在没有修改SDK文件的情况下,这对我有用:
ant.properties:
custom_rules.xml:
我以棘手的方式解决了这个问题;这里是
要在具有多个源目录的android中构建库项目,首先转到 ant.properties 文件(对于linux,它是 build.properties )并添加 source.dir
对于lib项目, ant 使用
或 build.properties 文件中指定的 bin/classes 目录 bin/classes 目录中的 .class 文件创建 jar 库;
在创建 jar 时, ant 从 jar 中删除所有 .java 源文件,如果编码器在 out.dir 目录中保留任何 .java 源文件,则可以包含在 jar 中,并在 source.dir 中指定该目录;
现在使用以下命令删除 .java 源 ant 进入 source.dir 目录
用这个命令 ant 实际上试图去目录
哪个不存在......
Solution:
步骤1.首先确保 source directory (source.dir)和 build directory (out.dir)不同;
第2步 . 转到C:\ Program Files \ Android \ android-sdk \ tools \ ant打开 build.xml 然后转到 jar 标签
现在注释或删除 jar 标记中的最后一个 fileset 标记
现在 Build 你的项目;
在项目目录中创建一个目录(比如build_src) .
进入那个目录(cd build_src)
在build_src中创建要包含的所有源目录的软链接(ln -s TARGET linkname),例如:如果您的原始问题是包含src1,src2和标准src目录,请创建src1,src2软链接到build_src下的那些
使用source.dir = build_src创建ant.properties
这对我来说很好,我认为是最干净的方法(因为那些是实际来源的软链接,你没有多个来源副本)
至少在构建工具的更高版本上,问题是放入此属性的值会传递到
<property name="source.absolute.dirs" location="source.dirs"/>
.location
属性不知道如何处理冒号/分号分隔的路径 .修复非常简单,只需使用:
等,而不是: