简体   繁体   English

来自Android库项目的R.java文件未导入到应用程序项目中

[英]R.java file from Android library project not importing into application project

I followed the instructions here on how to create an Android library project, and use it in an Android application: 我按照这里的说明如何创建Android库项目,并在Android应用程序中使用它:

http://developer.android.com/guide/developing/eclipse-adt.html http://developer.android.com/guide/developing/eclipse-adt.html

but it is not working. 但它不起作用。 I can see the library project is added to my application but I cannot reference anything in it because it won't build. 我可以看到库项目已添加到我的应用程序中,但我无法引用其中的任何内容,因为它不会构建。 The R.java file from the lib is NOT being added to my application project, so the lib project contains tons of errors, everywhere it tries to reference it's own R.java file. 来自lib的R.java文件没有被添加到我的应用程序项目中,因此lib项目包含大量错误,无论它在哪里尝试引用它自己的R.java文件。

I don't know if this has anything to do with it, but in the console there are messages stating that the there is "No resource identifier found for attribute 'X' in package 'Lib Package'. My library package has aa few styleable attributes defined for a custom view I made, all of which are being complained about in this console message. The library builds just fine, and I don't get those messages in the console until I hook the library to my application, so I don't know what's up with this. 我不知道这是否与它有任何关系,但是在控制台中有消息说“在包'Lib包'中没有找到属性'X'的资源标识符。我的库包有一些样式我为自定义视图定义的属性,所有这些都在这个控制台消息中被抱怨。库构建得很好,我没有在控制台中获取这些消息,直到我将库挂钩到我的应用程序,所以我不喜欢我不知道这是怎么回事。

I really would like to get this working. 我真的很想让这个工作。 I've spent two entire days on it, to no avail. 我花了整整两天时间,但没有用。 Please offer any ideas you might have to help! 请提供您可能需要帮助的任何想法!

The answer to my conundrum was that the library had an attrs.xml file that defined a few custom attributes for a custom view I created. 我的难题的答案是该库有一个attrs.xml文件,它为我创建的自定义视图定义了一些自定义属性。 I removed attrs.xml and hardcoded the values in the custom view code, rebuilt the library, and problem solved. 我删除了attrs.xml并在自定义视图代码中硬编码了值,重建了库,并解决了问题。

This isn't cool though, what this means is that custom views with custom attributes can't be used in libraries. 但这并不酷,这意味着具有自定义属性的自定义视图无法在库中使用。 I hope Google fixes this. 我希望谷歌能够解决这个问题。

It's actually a matter of file duplicity. 这实际上是文件的两面性问题。 You can't build a project that contains more than one instance of the same file. 您无法构建包含同一文件的多个实例的项目。 Due to the nature of an android project XML files are usually the first the negate a successful build. 由于android项目的性质,XML文件通常是否定成功构建的第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM