[英]How do I reference external jar files in a common directory (not libs) to build android project using ant?
I would like to build several android projects that reference the same jar files using ant. 我想建立几个使用ant引用相同jar文件的android项目。 I do not want to copy the jar file to each libs directory in the project (due to how the source control tree is set up).
我不想将jar文件复制到项目中的每个libs目录(由于如何设置源代码管理树)。 The answers I find here say "put them in the libs directory" which does not solve this problem.
我在这里找到的答案说“将它们放入libs目录”,这不能解决此问题。
So the question is, how do I configure my android ant build scripts to reference a common jar in a separate directory outside the project (not in "libs")? 所以问题是,我该如何配置我的android ant生成脚本以引用项目外部单独目录(而不是“ libs”中)的通用jar?
In the sdk, there are ant files under tools/ant
. 在sdk中,
tools/ant
下有ant文件。 In main_rules.xml
, you can find the following code section: 在
main_rules.xml
,您可以找到以下代码部分:
<!-- Directory for the third party java libraries -->
<property name="jar.libs.dir" value="libs" />
<property name="jar.libs.absolute.dir" location="${jar.libs.dir}" />
<!-- create a path with all the jar files, from the main project and the
libraries -->
<path id="jar.libs.ref">
<fileset dir="${jar.libs.absolute.dir}" includes="*.jar" />
<path refid="project.libraries.jars" />
</path>
This is how the ant build code determines where to get the jars from. 这就是蚂蚁构建代码确定从何处获取jar的方式。 You could overload the value of
jar.libs.dir
in your build.properties since that is read before this section and would overload the value. 您可以在build.properties中重载
jar.libs.dir
的值,因为这是在本节之前读取的,并且会重载该值。 Pointing that at a common directory you intend to use will do what you are suggesting. 将您打算使用的公用目录指向您将要执行的建议。 You may need to play with it some to get it to work the way you want.
您可能需要对其进行一些操作才能使其按所需的方式工作。
One caveat is that I'm not sure if this will negatively impact other build life cycle activities. 一个警告是,我不确定这是否会对其他构建生命周期活动产生负面影响。
It looks like the newer sdk tools make this easier to accomplish. 看起来,较新的SDK工具使此操作更容易实现。 I have a master libs folder that all my android projects share and I just added this to the
ant.properties
file to make it look up one level for those libs. 我有一个主libs文件夹,我所有的android项目都共享该文件夹,我刚刚将此文件夹添加到
ant.properties
文件中,以使其在这些lib的一级查找。
jar.libs.dir=../libs
As per the question here and my answer taken from here , the offered solution does not work as of now. 按问题在这里和我的答案取自这里 ,所提供的解决方案不作为现在的工作。 Until the filed bug is fixed.
直到已解决的bug修复。 The solution, as mentioned in the referenced answer, is copied below.
如参考答案中所述,该解决方案复制如下。
I add this to my custom_rules.xml
template and it seems to be working fine. 我将此添加到我的
custom_rules.xml
模板中,似乎工作正常。 I supposed it's only a few more lines than adding path to the ant.properties
file until we get a better solution. 我认为这只是比将路径添加到
ant.properties
文件多几行,直到我们得到一个更好的解决方案。
<target name="-pre-compile">
<path id="project.all.jars.path">
<path path="${toString:project.all.jars.path}"/>
<fileset dir="${jar.libs.dir}">
<include name="*.jar"/>
</fileset>
</path>
</target>
If you use Linux, just make symbolic links of the external jar files, then place them all in libs
. 如果使用Linux,则只需建立外部jar文件的符号链接,然后将它们全部放入
libs
。 Ant will work fine. 蚂蚁可以正常工作。
Edited 已编辑
Make sure place all symbolic links directly in libs
(not sub directories). 确保将所有符号链接直接放置在
libs
(而不是子目录中)。 I'm sure this can be re-config by ant script. 我确定可以通过ant脚本重新配置。 But I'm not familiar with ant :-)
但是我对蚂蚁不熟悉:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.