How to build an android app with external libraries using ant?

25,648

Solution 1

but the build fails because it's not building with some jarfiles I have in my libs directory.

And your error message is...what? I suspect you may be misinterpreting the error message.

I'd like to figure out the proper way to tell ant to build with some external jar files in my libs directory. How should I do this?

Just put them in libs/, as Ant will add everything in there to your build path. See this project, and this project, and this project for examples.

Solution 2

I spent some time trying to get the Facebook API to work with ant. The trick for me was to add this to my default.properties files.

android.library.reference.1=../Facebook

Where ../Facebook contains AndroidManifest.xml, etc. The real key being the relative path. Don't use an absolute path because Ant seems to treat your project directory as the root.

This should hold true for other library projects that you are including from source code.

Solution 3

I was dealing with similar issue. I'm building Android project on Jenkins using standard Ant build.xml (generated by Android SDK). I also have reference to another Java project with some shared domain classes. In Eclipse there is no problem with it. The domain project is a project reference. However on Jenkins this domain.jar is built by Maven and it was not accessible by Android project.

I have finally solved it by adding this at the end of build.xml:

<target name="-pre-build">
  <copy todir="${jar.libs.dir}">
    <fileset 
      dir="../path-to-another-project/target" 
      includes="*.jar" />
  </copy>
</target>

This copies all jars from the target directory of another project into "libs" directory of my Android project. The -pre-build Ant target is automatically called before Android compilation starts.

Solution 4

I agree with Mark, however, if you're planning to modify your build script further - than you need to make it custom. Bring tasks from android/platforms/android-PLATFORMVERSION/templates/android_rules.xml to your build.xml and modify whatever you want to modify. Including location for external libs.

Share:
25,648
emmby
Author by

emmby

Author of Android Application Development for Dummies. Author of RoboGuice, as well as the OpenTable, TripIt, and Digg Android applications. bebop Mobile at Google http://about.me/michaelburton

Updated on July 09, 2022

Comments

  • emmby
    emmby almost 2 years

    I have an existing project that builds fine using my IDE. I'd like to use the "android update" command to generate an ant buildfile for this project.

    The buildfile is generated fine, but the build fails because it's not building with some jarfiles I have in my libs directory.

    I'd like to figure out the proper way to tell ant to build with some external jar files in my libs directory. How should I do this? Is it a property in build.properties? Do I need to modify build.xml somehow? Or is there a different solution entirely?