How do I reference external jar files in a common directory (not libs) to build android project using ant? How do I reference external jar files in a common directory (not libs) to build android project using ant? android android

How do I reference external jar files in a common directory (not libs) to build android project using ant?


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>

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.


It looks like the newer sdk tools make this easier to accomplish. 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.

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. 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.I supposed it's only a few more lines than adding path to the ant.properties file until we get a better solution.

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