Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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")?

like image 492
icecream Avatar asked Mar 15 '11 13:03

icecream


People also ask

Where is JAR file in Android project?

If you are unable to find the libs folder in Android studio then open your android project in “Project” mode If the project is already opened in the “Android” mode. Then go to Your Project Name > app > libs and right-click on it and paste the downloaded JAR files.

How do I create a JAR file with an external library?

You can right-click on the project, click on export, type 'jar', choose 'Runnable JAR File Export'. There you have the option 'Extract required libraries into generated JAR'.


1 Answers

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.

like image 74
Nick Campion Avatar answered Oct 26 '22 11:10

Nick Campion