Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to distribute an Android Library

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.

like image 818
bianca Avatar asked Mar 06 '13 18:03

bianca


1 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.

like image 174
hakkikonu Avatar answered Oct 17 '22 10:10

hakkikonu