本文介绍了Android的图书​​馆项目已编译的JAR库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个自定义视图的API。为了使视图有在XML自定义属性我想用Android的图书​​馆项目的API。通过这一点,我可以宣布我的自定义的定义在attrs.xml属性。

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.

但我有问题,将其导出到一个JAR文件时所使用的图书馆项目。该项目引用JAR得到与包括在JAR android的资源文件的问题。有谁知道如何做到这一点?希望我已经清楚我的问题。
我不能让这个项目在这种情况下,一个开源项目。

But I'm having problems to use the Library Project when exporting it to an JAR-file. The project referencing 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.

[更新]
来源:的

你不能将库项目导出到一个JAR文件
库不能分发为二进制文件(如一个jar文件)。这是因为库项目由主体工程使用正确的资源ID编。

"You cannot export a library project to a JAR fileA 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."

所以我想那种回答我的问题。我已经尝试了一半的工作方案。这是生成Java源文件的JAR和只添加了Android XML资源,attrs.xml到谁使用JAR每个项目。但它不是我想要实现的东西一个很好的解决方案。我想与源和XML资源,JAR,但还没有找到一个解决方案这一点。

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.

推荐答案

从的的自定义XML属性,...如果你有这些工具R17

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.

专门从该链接的文本:

看一看到什么是在SDK R17新的

增加了对库中的自定义属性自定义视图支持。
  使用自定义属性的布局必须使用命名空间URI
  而不是URI那
  包括应用程序包名称。这个URI替换为应用程序
  特定的一个在构建时。

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.

这篇关于Android的图书​​馆项目已编译的JAR库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:21