Create an Android Jar library for distribution Create an Android Jar library for distribution android android

Create an Android Jar library for distribution


If you create a Android Library project without having any resources, the ADT (first noticed in r16) will create a .jar with the same name as the project in the 'bin' folder.


Android doesn't provide a special kind of Android-JAR. But what you can do is adding a build.xml to your project and build the JAR with ant.

My build.xml looks like this:

<project name="MyAndroidLib" default="dist" basedir=".">  <description>This is my Android lib  </description>  <!-- set global properties for this build -->  <property name="src" location="src" />  <property name="bin" location="bin" />  <target name="jar">    <jar destfile="MyAndroidLib.jar" basedir="bin/classes/">      <!-- replace 'com' by what ever you are using -->      <!-- as first part of the package name -->      <!-- e.g. de, org, ... -->      <!-- the ** is important to include the directory recursively -->      <include name="com/**" />    </jar>  </target></project>

Build the JAR by running ant jar in your projects main folder.


You can create a "regular" Java project and import from there Android.jar. Then, you will have access to every component in the SDK. Then, you can export your project as jar... and load it from your Android app. This works great and it seems a preety straightforward way to do it.