且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在公共目录(不是库)中引用外部 jar 文件以使用 ant 构建 android 项目?

更新时间:2023-09-30 15:28:40

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