【问题标题】:Duplicate value for resource 'attr/font' with config "带有配置的资源“attr/font”的重复值“
【发布时间】:2017-12-06 06:54:18
【问题描述】:

我现在真的知道为什么会得到这个error 以及如何解决它。 实际上,我不确定在收到 error 之前我做了什么。

错误信息: /Users/hyun/.gradle/caches/transforms-1/files-1.1/appcompat-v7-27.0.1.arr/25699caf34fef6313d6ec32013a1a117f/res/values/values.xml 错误:资源 'attr/font' 与配置的重复值”。 错误:这里之前定义的资源

/Users/hyun/Desktop/Laftel-Android/app/build/intermediates/incremental/mergeDbugResources/merged.dir/values/values.xml 资源 'attr/font' 的重复值与配置“。 之前在这里定义的资源。

Java.util.concurrent.ExecutionException:com.android.tools.appt2.Aapt2Exception:AAPT2 错误:检查详细信息任务“:app::mergeDebugResources”执行失败。 错误:java.utilconcurrentExcutionException:com.android.tools.aapt2.Aapt2Exception:AAPT2 错误:查看日志了解详情

【问题讨论】:

  • 今天莫名其妙地开始出现这个错误,我不知道发生了什么,所以出现这种情况,您设法找到解决方案吗?我整天都在看,一无所获。
  • 是的!首先,如果您使用的是排版库,请放弃此库。第二 - complieSdkVersion 27 - buildTollsVersion 27.0.2 - 将所有 com.android.support 库设为 27.0.2 希望你能解决问题
  • 错误在这里继续:/
  • 27.0.2 版本有一些 CollapsingToolbarLayout 的错误,这就是我需要使用 25.4.0 的原因。有什么帮助吗?
  • 通过清理和重建解决! ??????☺

标签: android android-resources


【解决方案1】:

这可能与我们之前用于应用自定义字体的逻辑产生冲突的概念。

以前

我们使用下面的代码来创建字体的自定义属性。

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

我改变了什么

就我而言,这就是问题所在,我通过重命名 attr 名称解决了这个问题

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

如果您使用任何第三方库或具有 "font" 属性的自定义视图

,这同样适用

根据reverie_ss 的建议,请检查您的 res->values->attrs.xml

【讨论】:

  • 如果有人找不到它,请检查您的 res->values->attrs.xml
  • 这为我指明了正确的方向。我还必须将诸如 R.styleable.com_my_app_font 之类的 Java 代码更新为 .....fontName。
  • 如何解决作为aar的自定义库属性
【解决方案2】:

支持库 26 为 TextView 等 XML 元素添加了字体属性。在我的例子中,我使用了一个带有自定义视图和自定义属性 app:font 的库,所以它们发生了冲突。将库属性重命名为其他名称(textFont)后,一切都恢复正常。那么,您是否在某处使用自定义“字体”属性?您最近是否将 Gradle 更新为 supportLibrary 26 或 27?如果无法覆盖属性名,请尝试回滚到 25

【讨论】:

  • 你是如何重命名库属性的?你有没有改变库的来源
  • 是的,它是我们自己开发的私有库,所以我们可以完全访问代码。
【解决方案3】:

迁移到 AndroidX 后,我的错误消息是

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

我为自定义视图定义了一个自定义属性,如下所示:

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

将进度重命名为 progressValue 解决了该问题。

【讨论】:

  • 遇到了同样的问题,你让我的生活更轻松了
【解决方案4】:

我将我的 android-X 库更新到了较新的版本,我在 styles.xml 中遇到了这种类型的错误

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

这是我之前的代码

<declare-styleable name="CircleProgressBar">
    <attr name="min" format="integer" />
    <attr name="max" format="integer" />
    <attr name="progress" format="integer" />
    <attr name="progressbarColor" format="color" />
    <attr name="progressBarThickness" format="dimension" />
</declare-styleable>

我更改了progress 属性值,将其重构为progressValue,如下所示。

<declare-styleable name="CircleProgressBar">
    <attr name="min" format="integer" />
    <attr name="max" format="integer" />
    <attr name="progressValue" format="integer" />
    <attr name="progressbarColor" format="color" />
    <attr name="progressBarThickness" format="dimension" />
</declare-styleable>

它对我有用。

【讨论】:

    【解决方案5】:

    我正在使用支持库 27.1.1 并且肯定 targetSDKVersion 是 27。在我的情况下与其他库发生冲突 这是谷歌播放服务,它也添加了支持库但使用旧版本,所以有两个库会产生问题。

    在项目级 build.gradle 文件中添加这个

    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"
                }
            }
        }
    }
    

    我在这里找到了这个link

    【讨论】:

    • 这个解决方案有什么作用?
    • 据我了解,当您针对 SDK 版本 27 或更高版本时,它对所有使用支持库的依赖项使用“26.1.0”支持库版本。
    【解决方案6】:

    如果您要迁移到 androidx,请尝试将以下代码放入 gradle.properties,如果您的项目目录中不存在此文件,请创建一个并放入以下行。这解决了

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

    我的错误

    android.enableJetifier=true
    android.useAndroidX=true
    

    【讨论】:

    • 在我的情况下似乎仍然出现错误:AAPT: 错误:资源 'attr/progress' 的重复值与配置
    【解决方案7】:

    我也有这个问题...

    我的问题:我在两个 xml 中使用了相同的属性名称(例如 editable):attr_1.xmlattr_2.xml

    attr_1.xml:

    <resources>
        <declare-styleable name="CustomContainerEditText">
            <attr name="android:text" format="string" />
            <attr name="editable" format="string" />
        </declare-styleable>
    </resources>
    

    attr_2.xml:

    <resources>
        <declare-styleable name="CustomContainerEditText">
            <attr name="editable" format="string" />
        </declare-styleable>
    </resources>
    

    解决方案: (简答)我只是从一个 xml 属性文件(如 attr_2.xml)中删除 format="String" 并修复了我的问题。

    attr_2.xml:

    <resources>
        <declare-styleable name="CustomContainerEditText">
            <attr name="editable" />
        </declare-styleable>
    </resources>
    

    【讨论】:

      【解决方案8】:

      尝试编译SdkVersion 25,然后一切正常。 支持 library 26 为 TextView 等 xml 元素添加了 font 属性,所以如果你想使用 sdkversion 26 那么你需要将 library 属性重命名为其他东西(textFont),一切又好了

      【讨论】:

        【解决方案9】:

        重复 实现 'com.android.support.constraint:constraint-layout:2.0.4'

        我删除它。

        【讨论】:

          【解决方案10】:

          在我的情况下:错误:资源“attr/mode”的重复值与配置“”

          它与以下库直接相关

          implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
          

          我不得不将名为 modedeclare-styleable 重命名为 custom_mode 之类的名称。然后它修复了错误。

          【讨论】:

            【解决方案11】:

            在我的情况下, textColor 和 text_background_color 正在造成问题,但在添加格式后它工作正常 添加格式之前

            <declare-styleable name="OtpView">
                <attr name="android:inputType">number</attr>
                <attr name="textColor"/>
                <attr name="OtpView_android_textColor" />
                <attr name="text_background_color"/>
                <!--<attr name="text_background_color" format="color">?back_icon_color</attr>-->
                <attr name="otp" format="string" />
                <attr name="lineColor" format="reference|color" />
            </declare-styleable>
            

            将格式添加到 textColor 和 text_beckground_color 属性后,它得到解决

            <declare-styleable name="OtpView">
                <attr name="android:inputType">number</attr>
                <attr name="textColor" format="string"/>
                <attr name="OtpView_android_textColor" />
                <attr name="text_background_color" format="string"/>
                <!--<attr name="text_background_color" format="color">?back_icon_color</attr>-->
                <attr name="otp" format="string" />
                <attr name="lineColor" format="reference|color" />
            </declare-styleable>
            

            【讨论】:

              【解决方案12】:

              只需不断降低路径中提到的依赖项的版本
              在您的情况下,它是:/Users/hyun/.gradle/caches/transforms-1/files-1.1/appcompat-v7 -27.0.1.arr/25699caf34fef6313d6ec32013a1a117f/res/values/values.xml

              所以减少 appcompat-v7-27.0.1 的版本号到 27.0.0 可能会起作用。

              如果它不起作用,则继续减少版本号并每次重新构建项目,直到它起作用为止。

              【讨论】:

                【解决方案13】:

                我遇到了同样的问题。 就我而言,我只是有

                implementation 'com.android.support:appcompat-v7:28.0.0'
                

                我加了

                implementation 'com.android.support:design:28.0.0'
                implementation 'com.android.support:support-v4:28.0.0'
                

                它对我有用!

                【讨论】:

                  猜你喜欢
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2019-08-10
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  相关资源
                  最近更新 更多