Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error:Attribute "color" has already been defined, update appcompat v-7

I am trying to update my appcompat-v7 in Android Studio project from v20.0.0 to 21.0.0 for use material design component but I allways get the same error:

"Error:Attribute "color" has already been defined"

I have not idea about what to do for fix this error, I searched in internet but I cant get the answer. Here is my gradle:

android {

    compileOptions.encoding = "iso-8859-1"
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.test"
        minSdkVersion 11
        targetSdkVersion 22
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
 compile 'com.android.support:support-v4:20.0.0'
    compile 'com.google.http-client:google-http-client-gson:1.19.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile "com.android.support:appcompat-v7:21.0.+"

}

Here is the path where the conflict exist

C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.3\res\values\values.xml

and this is other error:

Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    C:\Users\Abel Dominguez\AppData\Local\Android\sdk1\build-tools\build-tools-21.1.1\aapt.exe package -f --no-crunch -I C:\Users\Abel Dominguez\AppData\Local\Android\sdk1\platforms\android-21\android.jar -M C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\res\debug -A C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\assets\debug -m -J C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\generated\source\r\debug -F C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\res\resources-debug.ap_ --debug-mode --custom-package com.wherefriend -0 apk --output-text-symbols C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\symbols\debug
Error Code:
    1
Output:
    C:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\res\debug\values\values.xml:94: error: Attribute "color" has already been defined
like image 831
AbelMorgan Avatar asked Mar 08 '15 15:03

AbelMorgan


2 Answers

My problem was solved after I read the answer by @petey. If you look at the line displayed in error message you can precisely determine which attribute is causing problem.

In my case, it was an attribute named color in a custom attrs xml file. That custom view wasn't used so I just commented that line and problem was solved.

Possible solution steps

  1. Check error output to find the path to the file and line number that is causing problems

  2. Go to that file through your file system explorer and look for the line in question

  3. That line should mention what (custom) view has an attribute that is already defined somewhere.

  4. Back in the project in you IDE, find that attribute and if it is not used comment, otherwise if it IS used, change it's name.

like image 106
mdzeko Avatar answered Oct 12 '22 17:10

mdzeko


You should remove this line

compile 'com.android.support:support-v4:20.0.0'

and use the same dependency used by appcompat:

compile 'com.android.support:support-v4:21.0.+'

Also I suggest to fix the 21.0.3 instead of 21.0.+

like image 3
Gabriele Mariotti Avatar answered Oct 12 '22 15:10

Gabriele Mariotti