Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

ant

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?

like image 443
emmby Avatar asked Mar 17 '10 19:03

emmby


3 Answers

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.

like image 59
CommonsWare Avatar answered Nov 13 '22 07:11

CommonsWare


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.

like image 27
akitaben Avatar answered Nov 13 '22 09:11

akitaben


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.

like image 8
petrsyn Avatar answered Nov 13 '22 09:11

petrsyn