Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Android cannot deal with Resources name conflict between Project and Library?

I have a project A that referenced by Library B, A and B have the same name and type, but their value are different. I think aapt should deal with this issue that make sure project and library access the correct value. besides renaming all the resource in project or library, what else should I do to solve this problem?

like image 837
handrenliang Avatar asked May 03 '13 03:05

handrenliang


People also ask

How do I manage resources in Android?

Resource Manager is a tool window for importing, creating, managing, and using resources in your app. You can open the tool window by selecting View > Tool Windows > Resource Manager from the menu bar or by selecting Resource Manager on the left side bar. Click Add to add a new resource to your project.

In which folder does the Android project store its resources?

All graphics, strings, layouts, and other resource files are stored in the resource file hierarchy under the res directory. res/layout - XML layout files that describe the views and layouts for each activity and for partial views such as list items.

What are resource files in Android?

Resources are the additional files and static content that your code uses, such as bitmaps, layout definitions, user interface strings, animation instructions, and more. You should always externalize app resources such as images and strings from your code, so that you can maintain them independently.


2 Answers

The build system intentionally makes all project resources overlay on top of the library resources. This is done on purpose to be able to customize a library resource differently depending on the app using it.

If you want to prevent this happening without your knowledge we have always recommended users to use prefix in the library resources.

Changing the behavior at this point would break many, many people's projects. We've looked at making it an option, but it won't happen before the new build system is finished though.

like image 194
Xavier Ducrohet Avatar answered Oct 14 '22 21:10

Xavier Ducrohet


As per the Android Building process, all projects and libraries (and all of the resources in all of them) are combined as part of the apkbuilder process. If there is a conflict between your project and library (or between two libraries), the final build will not know which to reference as they share the same name. Of course, this has benefits in that you can reference library resources in your project by name, even though the underlying build process is de-conflicting the underlying ids.

like image 37
ianhanniballake Avatar answered Oct 14 '22 22:10

ianhanniballake