Hein Htet Aung
Hein Htet Aung

Reputation: 854

Attr value is declared in two different libraries

I added a library to my project in Android Studio. But as soon as I tried to compile my project I got this error:

Attribute barColor has already been declared.

After that I checked the whole project and noticed that another library is already declaring that same attribute!

How can I fix this conflict or can I just not use those libraries at the same time?

enter image description here

The libraries which are causing the conflict are:

Upvotes: 2

Views: 919

Answers (2)

user9113430
user9113430

Reputation:

Create a new folder and name it like this values-v21 then put that particular xml file like attr.xml that causing a duplication to that folder. By doing it will not confuse or merge the two identical resources, but of course by doing this you say that this attr will be use only starting from sdk 21 and above depends on what sdk version you will provide.

Upvotes: 1

Xaver Kapeller
Xaver Kapeller

Reputation: 49817

The easiest fix for this is to just rename the attribute in one of the libraries. To do that you have to:

  1. Download the source code of one of the libraries and add it to your project.
  2. Now you have to rename the attribute in the source code you just downloaded. The simplest way to do that is through refactoring. So right click on the attribute in question and select refactoring -> rename. Alternatively just place your cursor on the attribute and hit Shift + F6. Then enter a new name for the attribute.
  3. Most of the time the refactoring should already do all the work for you, but sometimes you need to fix a few things manually after refactoring. Just try rebuilding your project until you don't get any compile errors and fix errors as they come up.

After that you should be all set. Now that the attributes have different names there shouldn't be any conflict!

Upvotes: 0

Related Questions