Create an Android Jar library for distribution

Solution 1:

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.

Solution 2:

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.

Solution 3:

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.

Solution 4:

just go to properties of the project of which you want to make jar.Click on Android tab. and tick in the Is library. now you can see .jar file in the bin folder.use it where you want to use.

Solution 5:

The only solution 'officially supported' by Google is the Library project, and it requires the source code to be distributed. You can create a JAR in the normal way, but you cannot include or reference resources within it.

Unfortunately I think it is also not possible to include a packaged JAR within a Library project, as a means to get around the source code requirement.