如何在公共目录(不是库)中引用外部 jar 文件以使用 ant 构建 android 项目? [英] How do I reference external jar files in a common directory (not libs) to build android project using ant?

查看:28
本文介绍了如何在公共目录(不是库)中引用外部 jar 文件以使用 ant 构建 android 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建几个使用 ant 引用相同 jar 文件的 android 项目.我不想将 jar 文件复制到项目中的每个 libs 目录(由于源代码控制树的设置方式).答案找到这里说把它们放在 libs 目录中"这并不能解决这个问题.

I would like to build several android projects that reference the same jar files using ant. 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). The answers I find here say "put them in the libs directory" which does not solve this problem.

所以问题是,如何配置我的 android ant 构建脚本以引用项目外单独目录中的公共 jar(不在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")?

推荐答案

在sdk中,tools/ant下有ant文件.在main_rules.xml中,您可以找到以下代码部分:

In the sdk, there are ant files under tools/ant. In main_rules.xml, you can find the following code section:

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

这就是 ant 构建代码确定从何处获取 jar 的方式.您可以在 build.properties 中重载 jar.libs.dir 的值,因为它是在本节之前读取的,并且会重载该值.指向您打算使用的公共目录将执行您的建议.您可能需要对其进行一些操作才能使其按您想要的方式工作.

This is how the ant build code determines where to get the jars from. 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. 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.

这篇关于如何在公共目录(不是库)中引用外部 jar 文件以使用 ant 构建 android 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆