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

穿精又带淫゛_ 提交于 2019-12-01 04:40:26

问题


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?


回答1:


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.




回答2:


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.




回答3:


Import the appropriate R.java file to resolve the resource conflicts.

  1. Make sure that your package name and the library's package names are different.

  2. If you need your libraries resources then refer to them by library.packagename.R.drawable.resourceId and not by R.drawable.resourceId

  3. Check your gen files if it has 2 R.java files.



来源:https://stackoverflow.com/questions/16350957/why-android-cannot-deal-with-resources-name-conflict-between-project-and-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!