I have s开发者_如何学编程everal android constructs like custom dialog boxes, drag-and-drop implementations, and other standard classes that I use in multiple projects. It seems both inefficient and bad practice to put a copy of each construct (each with its own set of resources and classes to maintain) into each project. Now if I find a bug in these, I have to change it everywhere.
Good practice would dictate that I include that as a separate project, perhaps a jar library that my other projects can import. This works fine for constructs that are purely java classes, but some of these things have android resources associated with them and I don't know if there is a way to include those in a jar in a way the android resource compiler will recognize.
Is it even possible to build a jar with Android resources included (i.e. a custom dialog box with a custom background drawable or something)? If it is possible, how?
Never implemented this type of project but heard about Android library project. Maybe that's the solution for you.
You cannot include any resources or xml in your JAR. Jar can contain only contain .class files. So, an absurd practice is to package your jar with your resources and xml in a higher packaging method such as .zip or .rar. But its way too cumbersome for users. The best possible distribution method i can see around is, create a Library project, as instructed in the link provided above by FrVaBe, and distribute it as open sourced code. The Library Users will require to open this Library project while compiling the .apk for their project which is using the Library, so that the required resources and files get packaged with the .apk...
精彩评论