Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: Attribute "***" has already been defined when using two library projects in Android

I'm using android-support-v7-appcompat as a library in my Android project. Now I want to include actionbarsherlock as another library project. When I add the second library, it gives so many errors like below

android-support-v7-appcompat\res\values\attrs.xml:476: error: Attribute "attributeName" has already been defined

By changing one attribute value and it's related code snippet is a one solution that I've tried. But when there are nearly 80 lines like above, it will get a messy. Is there any other way I can solve this issue?

like image 358
AnujAroshA Avatar asked Nov 15 '13 07:11

AnujAroshA


3 Answers

The correct way to solve this problem is by updating Android Support Libraries in all relevant projects and library projects. In my case I've used Android support library and also one of the library project to implement my application. When I update both libraries, the problem solved. The way of updating Android support library is;

  • Right click on the project
  • Select Android Tools from the pop up window
  • Select Add Support Library
like image 111
AnujAroshA Avatar answered Nov 20 '22 06:11

AnujAroshA


Remove the appcompact support library project from Properties = > Android

like image 3
HimalayanCoder Avatar answered Nov 20 '22 06:11

HimalayanCoder


Gradle Resource Merger merges all resource folders from all dependencies and place into single folder. In case there are duplicates build process will fail.

Fortunately, if you look below under Output: label, you will find the right path to the problem.

Here is an example

enter image description here

in your case it is android-support-v7-appcompat\res\values\attrs.xml:476: error: Attribute "attributeName" has already been defined

You can also build your project from command line and get the right path. attributeName Inside values\attrs.xml file on line 476 you would find a with property named "attributeName". Most probably it is your own styleable that you have to change to get rid of the duplicate.

So now, when you know the reason, you can locate that property in your project module and replace it with different name.

like image 3
dmSherazi Avatar answered Nov 20 '22 08:11

dmSherazi