Android Library Project as compiled JAR library
I am creating an API with a custom view. In order to enable the view to have custom attributes in the XML I want to use the "Android Library Project" for the API. By this I can declare the definition of my custom attributes in an attrs.xml.
But I'm having problems to use the Library Project when exporting it to an JAR-file. The project referencin开发者_StackOverflow中文版g the JAR gets problems with the android resource files included in the JAR. Does anyone know how to accomplish this? Hope I've been clear in my question. I cannot let the project be an open source project in this case.
[Update] From: http://developer.android.com/guide/developing/projects/index.html#considerations
"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 is because the library project is compiled by the main project to use the correct resource IDs."
So I guess that kind of answers my question. I've tried a half working solution. It is to generate a JAR from the java source files and add only the Android xml resources, as attrs.xml to each project who use the JAR. But it is not a good solution for the thing I want to achieve. I want a JAR with both source and xml resources but haven't found a solution for this.
an update from code.google.com Issue 9656: Library projects don't support custom XML attributes for custom classe, … if you have r17 of the tools.
specifically from the text of that link:
Take a look into "what's new in sdk r17":
Added support for custom views with custom attributes in libraries. Layouts using custom attributes must use the namespace URI http://schemas.android.com/apk/res-auto instead of the URI that includes the app package name. This URI is replaced with the app specific one at build time.
worked for me like a charm today! i now have a library that contains my custom widget so i can use it in all my projects via reference.
In order to support faster build times, the r16 tools are creating their own jar files inside of Android Library Projects. You can use this feature to solve this issue. If you would like to release your Android Library Project but without source code, you can make a copy of that Android Library Project that contains everything except for the source code tree. Next, include the jar file from the original Android Library Porject (the one that the r16 tools built.) This will allow you to have a component you can distribute that does not require source code. The consumer of this new Android Library Project will need to manually add any necessary meta data to their own project's AndroidManifest.xml file as needed (Activities, Providers, Permissions, etc).
精彩评论