views:

31

answers:

1

Hi,

I'm pretty new to Android development, but I have some experience with Java and Eclipse. I'm looking for ways to create re-usable libraries (controls, helpers, "standard" activities, etc.) that I could use in my own projects, but that could also be distributed to other developers without disclosing the source code.

Normally, I'd package the class files into a JAR file and any other developer could add it to the classpath and use the packaged classes.

How can I do that with Android projects? I've read about Android Library Projects, but as the documentation states they can not be packaged into a JAR, but will be compiled along with the project that references the library project. This means I also have to distribute the source code.

I've also read this post, which asks about the same question but didn't provide a satisfying answer.

So: Is there a way of compiling and packaging a set of classes and other files (including XML layouts, resources and stuff) and distribute only that package without any source codes so that it can be "referenced" and used like a JAR file by any other developer?

+1  A: 

I've read about Android Library Projects, but as the documentation states they can not be packaged into a JAR, but will be compiled along with the project that references the library project. This means I also have to distribute the source code.

Not true. It does require a bit of extra packaging work, but you can compile your code to a JAR and distribute the JAR in the library project's libs/ directory.

So: Is there a way of compiling and packaging a set of classes and other files (including XML layouts, resources and stuff) and distribute only that package without any source codes so that it can be "referenced" and used like a JAR file by any other developer?

Use an Android library project. I have some stuff written up here that describes a bit more of the packaging options, plus pointers to some "parcels" that follow the conventions described therein.

CommonsWare
Thank you, this seems to be what I'm looking for. Even though I only gave it a quick read, I'll mark your answer as accepted answer, because it seems to actually get me somewhere :-)
Thorsten Dittmar
@Thorsten Dittmar: Please feel free to send me feedback on problems you encounter, through the `cw-android` Google Group. This is a fairly recent (and hasty) rewrite of this material to adopt library projects as the foundation, and I am sure I need to add more information here.
CommonsWare