0

I am trying to build my Android project with Ant. I have some reference libs which I defined in build.xml like below mentioned in this question:

<target name="-pre-compile">
<!-- HACK to add the android-support-v4.jar to the classpath directly from the SDK -->

    <echo>ORIGINAL jars.path : ${toString:project.all.jars.path}</echo>
    <path id="project.all.jars.path.hacked">
            <path path="${toString:project.all.jars.path}"/>
            <path path="${sdk.dir}/extras/android/support/v4/android-support-v4.jar"/>
    </path>

    <path id="project.all.jars.path">
            <path path="${toString:project.all.jars.path.hacked}"/>
    </path>
    <echo>HACKED jars.path : ${toString:project.all.jars.path}</echo>

</target>

I have no problem while compiling with my external jars and it builds apk properly.

My problem starts when I use an external lib having exact package similar to system package.

For example, I have some customized frameworks.jar and I have linked it to my project in the same fashion mentioned above. But ANT considers system frameworks and ignores my frameworks.jar.

This works fine in Eclipse when I order it and keep my custom frameworks.jar above system Android libs (Eclipse > Project > Right Click > Build Path > Configure Build Path > Order and Export)

Is there any way how we can define order of libraries to be consider while compiling by ANT. Like how we do it in Eclipse?

Community
  • 1
  • 1
AndroDev
  • 3,236
  • 8
  • 35
  • 49

1 Answers1

0

Just replace javac bootclasspath param to solve this problem.

The original bootclasspath is platform/android-xx/android.jar, and this class path has the the highest priority.

So we have to replace it with your own external jar, and replace it back after compile is finished to prevent proguard from adding platform/android-xx/android.jar to obfuscated.jar.

Code as follows:

<path id="project.org.path" >
</path>
<path id="project.org.android.jar" >
</path>

<target name="-pre-compile" >

    <path id="project.org.path" >
        <path path="${toString:project.all.jars.path}" />
    </path>

    <path id="project.org.android.jar" >
        <path path="${toString:project.target.class.path}" />
    </path>

    <path id="project.all.jars.path.hacked" >
        <path path="${toString:project.target.class.path}" />
        <path path="${toString:project.all.jars.path}" />
    </path>

    <path id="project.all.jars.path" >
        <path path="${toString:project.all.jars.path.hacked}" />
    </path>

    <path id="project.target.class.path" >
        <path path="./framework.jar" />
    </path>
</target>

<target name="-post-compile">
    <path id="project.all.jars.path" >
        <path path="${toString:project.org.path}" />
    </path>
    <path id="project.target.class.path" >
        <path path="${toString:project.org.android.jar}" />
    </path>
</target>
he.cao
  • 51
  • 2