Duplicate value for resource 'attr/font' with config "

一个人想着一个人 提交于 2019-11-26 05:35:59

问题


I really do now know why I got this error and how can I solve it. Actually I am not sure What I did right before I got this error.

Error Msg: /Users/hyun/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.0.1.arr/25699caf34fef6313d6ec32013a1a117f/res/values/values.xml error:duplicate value for resource \'attr/font\' with config\". error: resource previously defined here

/Users/hyun/Desktop/Laftel-Android/app/build/intermediates/incremental/mergeDbugResources/merged.dir/values/values.xml duplicate value for resource \'attr/font\' with config \". resource previously defined here.

Java.util.concurrent.ExecutionException:com.android.tools.appt2.Aapt2Exception:AAPT2 error: check for details Execution failed for task \':app::mergeDebugResources\'. Error: java.utilconcurrentExcutionException:com.android.tools.aapt2.Aapt2Exception : AAPT2 error: check logs for details


回答1:


It may the concept that makes conflicts with the logic that we have previously used for apply Custom fonts.

Previously

We have used below code for creating the custom attribute for the font.

    <declare-styleable name="CustomFont">
        <attr name="font" format="string" />
    </declare-styleable>

What I change

In my case, this was the issue and I have resolved it by renaming the attr name

    <declare-styleable name="CustomFont">
        <attr name="fontName" format="string" />
    </declare-styleable>

This same thing may apply if you are using any third party library or Custom View with "font" property

As per suggestion by reverie_ss Please Check your res->values->attrs.xml




回答2:


support library 26 added font attribute to XML elements like TextView, etc. In my case, I was using a library with custom views and a custom attribute app:font, so they collided. After renaming the library attribute to something else (textFont), all went good again. So, are you using a custom 'font' attribute somewhere? Did you update Gradle to supportLibrary 26 or 27 recently? If you can't override the attribute name, try rolling back to 25




回答3:


After migrating to AndroidX my error message was

error: duplicate value for resource 'attr/progress' with config ''

and I had a custom attribute defined for a custom view as the following:

<declare-styleable name="ProductionProgressItemView">
    <attr name="progressTitle" format="string"/>
    <attr name="progress" format="string"/>
    <attr name="progressPercent" format="integer"/>

renaming progress to progressValue fixed the issue.




回答4:


I am using supporting library 27.1.1 and definitely targetSDKVersion is 27. There was a conflict with other library in my case It was google play services which also adds supporting library but with older version so there are two libraries which creates issue.

Add this in project level build.gradle file

task clean(type: Delete) {
delete rootProject.buildDir
}

subprojects {
    project.configurations.all {
        resolutionStrategy.eachDependency { details ->
            if (details.requested.group == 'com.android.support'
                    && !details.requested.name.contains('multidex') ) {
                details.useVersion "26.1.0"
            }
        }
    }
}

I found this here link




回答5:


try compileSdkVersion 25, then it will be all ok. support library 26 added font attribute to xml elements like TextView, etc, so if you want to use sdkversion 26 then you need to renaming the library attribute to something else (textFont), all went good again




回答6:


If you are migrating to androidx, try putting the below code in gradle.properties, if this file doesn't exist inside your project directory create one and put the below lines. This solved

Duplicate value for resource 'attr/.*' with config ''

error in my case

android.enableJetifier=true
android.useAndroidX=true


来源:https://stackoverflow.com/questions/47668526/duplicate-value-for-resource-attr-font-with-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!