Error: the color attribute is already defined, update appcompat v-7

I am trying to upgrade my appcompat-v7 in an Android Studio project from v20.0.0 to 21.0.0 to use the material composition component, but I always get the same error:

Error: The color attribute is already defined.

I do not know what to do to fix this error, I searched the Internet, but I can not get an 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 in which there is conflict

 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 another 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 -IC:\Users\Abel Dominguez\AppData\Local\Android\sdk1\platforms\android-21\android.jar -MC:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -SC:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\res\debug -AC:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\intermediates\assets\debug -m -JC:\Users\Abel Dominguez\Documents\PROYECTOS_ANDROID\definitivos\d2\app\build\generated\source\r\debug -FC:\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 
+8
android appcompat
source share
4 answers

My problem was resolved after I read the answer from @petey. If you look at the line displayed in the error message, you can determine exactly which attribute is causing the problem.

In my case, it was an attribute named color in the user attrs xml file. This user view was not used, so I just commented that the problem has been resolved and resolved.

Possible Solution Steps

  • Check the error output to find the path to the file and the line number that causes the problem.

  • Browse to this file through the file system explorer and find the corresponding line.

  • This line should indicate which (custom) view has an attribute that is already defined somewhere.

  • Return to the project in the IDE, find this attribute and, if it is not used in the comment, otherwise, if it is used, change its name.

+14
source share

You must delete this line

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

and use the same dependency as appcompat:

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

I also suggest fixing 21.0.3 instead of 21.0. +

+3
source share

Gradle Resource Merge merges all resource folders from all dependencies and fits into one folder. In case the duplicate creation process fails.

Fortunately, if you look below in the Output: label method, you will find the correct 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 create your project from the command line and get the correct path. attributeName Inside the value of the \ attrs.xml file on line 476, you will find a property named "attributeName". Most likely, this is your own style, which you must change in order to get rid of the duplicate.

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

0
source share

In some cases, this may help you. However, this is not a specific answer.

 tools:attr markers 

In any particular element, there may be many attributes associated with attributes to resolve all conflicting attributes.

 <tools:strict="x, y, z"> 

The default implicit mode for an attribute generates an error when trying to declare an advertisement with a lower merge priority with a different value.

 <tools:remove="x, y, z"> 

Remove the x, y, z attributes from any lower priority merge ad.

 <tools:replace="x, y, z"> 

Replace the x, y, z attributes from any lower priority creative with the supplied value (must be present on the same node).

REF: http://tools.android.com/tech-docs/new-build-system/user-guide/manifest-merger#TOC-tools:attr-markers

0
source share

All Articles