简体   繁体   中英

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:

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.

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.

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. I removed attrs.xml and hardcoded the values in the custom view code, rebuilt the library, and problem solved.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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