How to distribute an Android Library
android, android-library, jar
Solution
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:
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.
Compile the Java source (e.g., ant compile) and turn it into a JAR file
- Create a distribution Android library project, with the same resources as the master library project, but no source code
- 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.
Problem
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.