Reputation: 535
I have a main android app which has 2 jars in it's libs folder. This android app includes a Java Source Project which has about 4 jars in it's libs folder.
In the build.xml I have copied from android's build.xml the 'target name="-compile">'.
and added this:
<do-only-if-manifest-hasCode elseText="hasCode = false. Skipping..." >
<!-- merge the project's own classpath and the tested project's classpath -->
<path id="project.javac.classpath" >
<path refid="project.all.jars.path" />
<path refid="tested.project.classpath" />
</path>
<javac
bootclasspathref="project.target.class.path"
classpathref="project.javac.classpath"
debug="true"
destdir="${out.classes.absolute.dir}"
encoding="${java.encoding}"
extdirs=""
fork="${need.javac.fork}"
includeantruntime="false"
source="${java.source}"
target="${java.target}"
verbose="${verbose}" >
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<src path="${javaproject.dir}" /> #THIS IS WHAT I ADDED which is defined in ANT.PROPERTIES
<compilerarg line="${java.compilerargs}" />
</javac>
So it references the java source project. The problem happens with the java source project's jars which are in folder libs. How do I also include them?
ps. copying them to android project's libs folder is not an option.
Upvotes: 0
Views: 896
Reputation: 1
It works for me to build an additional path following in David's solution. I added a if condition to check the additional lib path was needed or not.
<condition property="android.additional.libdir.enabled" value="true" else="false">
<and>
<isset property="android.additional.lib.dir" />
</and>
</condition>
<if condition="${android.additional.libdir.enabled}">
<then>
<path id="project.javac.classpath">
<path refid="project.all.jars.path" />
<path refid="tested.project.classpath" />
<fileset dir="${android.additional.lib.dir}">
<include name="**/*.jar"/>
</fileset>
</path>
</then>
<else>
<path id="project.javac.classpath">
<path refid="project.all.jars.path" />
<path refid="tested.project.classpath" />
</path>
</else>
</if>
In the ant.properties file, specify the additional lib directory path.
android.additional.lib.dir=yourpath
Upvotes: 0
Reputation: 107040
You have the following:
<javac
bootclasspathref="project.target.class.path"
classpathref="project.javac.classpath"
debug="true"
destdir="${out.classes.absolute.dir}"
encoding="${java.encoding}"
extdirs=""
fork="${need.javac.fork}"
includeantruntime="false"
target="${java.target}"
verbose="${verbose}"
source="${java.source}">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<src path="${javaproject.dir}" /> #THIS IS WHAT I ADDED which is defined in ANT.PROPERTIES
<compilerarg line="${java.compilerargs}" />
</javac>
Notice you've specified both the source
parameter and the <src path>
sub-entity. Also notice that you have a reference to javaproject.dir
. What is this directory? Is it the source of the other project, the other project's main directory, or something else?
First, you shouldn't use both <src path>
and the srcdir
parameters in your <javac>
command. If you need only a single source directory path, you can use either the srcdir
parameter of the <javac>
task, or the <src path>
sub-entity. If you have more than one, you should not use srcdir
, and only use the <src path>
sub-entity.
Now back to your question...
If I understand you correctly, you want to specify multiple classpath folders in your <javac>
task. You can do this by removing the classpath
or classpathref
parameters of the <javac>
command, and simply specify multiple <classpath path>
sub-entities like you do with source directories.
I think you want something like this:
<javac
bootclasspathref="project.target.class.path"
debug="true"
destdir="${out.classes.absolute.dir}"
encoding="${java.encoding}"
extdirs=""
fork="${need.javac.fork}"
includeantruntime="false"
target="${java.target}"
verbose="${verbose}">
<!-- Here I can specify multiple classpaths: -->
<!-- Either classpath references, or classpath elements -->
<classpath refid="project.javac.classpath"/>
<classpath refid="some.other.classpath.reference"/>
<classpath path="${some.actual.directory.with.jars}"/>
<src path="${java.source}">
<src path="${source.absolute.dir}" />
<src path="${gen.absolute.dir}" />
<!-- <src path="${javaproject.dir}" /> Is this correct? -->
<compilerarg line="${java.compilerargs}" />
</javac>
Upvotes: 1
Reputation: 2702
You can build a <path>
to contain all the jars your project depends on at build-time and reference it in your <javac>
task. You've already got the latter working with the classpathref to "project.javac.classpath", so you need to make that path include the jars.
For example:
<path id="project.javac.classpath">
<path refid="project.all.jars.path" />
<path refid="tested.project.classpath" />
<!-- include all the jar files under /path/to/your/jars" -->
<fileset dir="/path/to/your/jars">
<!-- the **/* pattern recurses subdirectories -->
<include name="**/*.jar"/>
</fileset>
</path>
That path includes a reference to "project.all.jars.path", which is probably where you really want to make the changes I noted to pick up the additional jars.
Upvotes: 0