Take the 2-minute tour ×

I've been spinning a jar for android library project and including this jar in my other apps. But on developer.android.com, I see this statement that I can't distribute a library in a jar:

  • You cannot export a library project to a JAR file

A library cannot be distributed as a binary file (such as a JAR file). This will be added in a future version of the SDK Tools.

I really don't understand what does that mean.

share|improve this question
add comment

2 Answers

It is possible to create an Android library project that does not include source code. The limitations are:

  • You still have to ship the resources.

  • You have to rewrite your code to avoid using R. values, as they will be wrong. You will have to look up all resource IDs using getResources().getIdentifier() and/or reflection.

I have the instructions in The Busy Coder's Guide to Advanced Android Development (http://commonsware.com/AdvAndroid), though the instructions are new enough that none of my free versions have them. Quoting some of the instructions from the current edition:

"You can create a binary-only library project via the following steps:

  1. Create an Android library project, with your source code and such – this is your master project, from which you will create a version of the library project for distribution.

  2. Compile the Java source (e.g., ant compile) and turn it into a JAR file

  3. Create a distribution Android library project, with the same resources as the master library project, but no source code
  4. Put the JAR file in the distribution Android library project's libs/ directory

The resulting distribution Android library project will have everything a main project will need, just without the source code."

Personally, I'd just wait a bit. I am hopeful that the official support for library-projects-as-JARs will be available soonish.

share|improve this answer
"You have to rewrite your code to avoid using R. values, as they will be wrong" -- I suspect that this is still an issue, though there's a chance that this requirement has been lifted. I need to run some more tests someday for that scenario. Also ant compile is now ant debug or ant release, as I don't think the compile Ant task is around anymore. Otherwise, this technique works -- it is how Google distributes the Play Services SDK, for use with things like Maps V2. –  CommonsWare Mar 6 '13 at 19:11
add comment

It means that (at the current time) you must distribute your entire project folder. Rather than just a jar file like you can for java libraries.

When someone wants to use your library they will import your project into eclipse, and then in project properties->android they will add your project as an android library.

A few common ways used to distribute a Library project are by using git, or zipping your project folder and making it available online.

share|improve this answer
add comment

Your Answer


