Search code examples
androidandroid-libraryname-conflict

Custom build script to avoid libraries name collisions?


When using Android libraries if more than one project (main or libraries) defines the same resource, the higher-priority project's copy gets used and replaces the previous one.

This is a problem when writing a reusable library because it forces you to prefix every resource name to avoid conflicts. See the Android Parcel Project for more information on the topic.

Now what I'd like to do is a script that would, prior to compilation, prefix the name of every resource from all libraries with their package name. For this I intend to use the generated ant build script and add a custom step to it.

Do you know if that would be possible? Do you see a better solution to fix this issue?


Solution

  • Do you know if that would be possible?

    If you have source code to the library, I suppose you could do this. Any place you refer to resource IDs dynamically (reflection, getIdentifier(), etc.) would have to be adjusted manually, I suspect. And you may not be able to get assistance from the library author given that you modified their code.

    I'd also work on trying to convince the library author to add resource prefixes in future editions of their library.