How to add external jar libraries to an android project from the command line How to add external jar libraries to an android project from the command line android android

How to add external jar libraries to an android project from the command line


Jay K's answer was right at the time of writing, but now the SDK has changed, and here is the new way to do it:

Add the following line to ant.properties:

jar.libs.dir=lib

Tested, works where external.libs.dir does not work.
That changed in December 2010 and then again in October 2011.


Just for future reference:Right now there is a bug in the SDK which prevents of using jar.libs.dir:http://code.google.com/p/android/issues/detail?id=33194

A simple solution to use jar.libs.dir again (while waiting for the bug to get fixed), is to add this target in the build.xml file:

<target name="-pre-compile">    <path id="project.all.jars.path">        <path path="${toString:project.all.jars.path}"/>        <fileset dir="${jar.libs.dir}">            <include name="*.jar"/>        </fileset>    </path></target>


At compiling do this:

javac -encoding ascii -target 1.5 -d bin/classes \-bootclasspath $SDKDIR/android.jar src/some/project/* -classpath=libs/*.jar

And, when you are generating the bytecode for Dalvik:

dx --dex --output=bin/classes.dex bin/classes libs/*.jar

Also, when you are packaging the APK file:

apkbuilder bin/something.apk -z bin/projectname.ap_ \-f bin/classes.dex -rf src -rj libs

I'm assuming you are using Linux... on Windows will be almost the same.