Why can't Android deal with a resource name conflict between Project and Library?

I have a project A, referenced by libraries B, A and B, have the same name and type, but their meaning is different. I think aapt should solve this problem to make sure that the project and library have access to the correct value. Besides renaming the entire resource in a project or library, what else should I do to solve this problem?

+4
source share
3 answers

The build system intentionally forces all project resources to overlap over library resources. This is done specifically to be able to configure the library resource differently depending on the application used.

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

Changing behavior at this stage will disrupt many, many projects. We considered the option, but this will not happen before the new build system is completed.

+8
source

In accordance with the Android Building process, all projects and libraries (and all resources in all of them) are integrated as part of the apkbuilder process. If there is a conflict between your project and the library (or between two libraries), the final assembly will not know for which links they have the same name. Of course, this has advantages in that you can refer to the library resources in your project by name, although the basic assembly process de-conflicts with the main identifiers.

+1
source

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

  • Make sure your package name and library package names are different.

  • If you need the resources of your libraries, refer to them at library.packagename.R.drawable.resourceId , not R.drawable.resourceId

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

0
source

Source: https://habr.com/ru/post/1478906/


All Articles