I am using a Referenced Library (Properties/Android/Library) in a parent project. The referenced library uses a color/transparent in one of its screens /layout files. The parent project also has a color/transparent, but with a different value than used in the referenced library's color/transparent. The referenced library's code uses the value in the parent project. I had to hard-code the referenced library's value to a specific value via android:background="#000000". Is there a way to let the referenced library use its own color value instead of inheriting the parent project's value for the same named attribute?

1 Answer
1

This is how Android Library Project is designed to work in Android SDK. Android Library Project is never built directly, it is always built indirectly when the dependent Main Project is built, when SDK compile/build the Main Project, the source and resource from Library Project is filtered and merged into Main Project. When same resource name is defined in both the main project and the library project, the one from main project always has the first priority.

However, a library project differs from an standard Android application project in that you cannot compile it directly to its own .apk and run it on an Android device. Similarly, you cannot export the library project to a self-contained JAR file, as you would do for a true library. Instead, you must compile the library indirectly, by referencing the library in the dependent application and building that application.

When you build an application that depends on a library project, the SDK tools compile the library into a temporary JAR file and uses it in the main project, then uses the result to generate the .apk. In cases where a resource ID is defined in both the application and the library, the tools ensure that the resource declared in the application gets priority and that the resource in the library project is not compiled into the application .apk. This gives your application the flexibility to either use or redefine any resource behaviors or values that are defined in any library.

The solution is rename the resource name in Main Project to something else like color/transparent2. Hope this help.

Thanks for the answer. Unfortunately not what I was hoping to hear, but it explains the behavior. Library projects are like Waffle House home fries: can't live with them, can't live without them.
–
charlestApr 15 '12 at 1:44