【问题标题】:Attribute already defined with incompatible format (Original attribute defined here)已使用不兼容格式定义的属性(此处定义的原始属性)
【发布时间】:2016-09-06 10:59:31
【问题描述】:

添加后无法构建项目

compile 'com.android.support:design:24.2.0'

不断出现以下错误:

似乎问题在于支持矢量可绘制对象。某处某些属性被添加了两次。

例如,构建的 values.xml 文件包含:

<declare-styleable name="AppBarLayout_LayoutParams"><attr name="layout_scrollFlags"><flag name="scroll" value="0x1"/><flag name="exitUntilCollapsed" value="0x2"/><flag name="enterAlways" value="0x4"/><flag name="enterAlwaysCollapsed" value="0x8"/></attr><attr format="reference" name="layout_scrollInterpolator"/></declare-styleable>

<declare-styleable name="AppBarLayout_Layout"><attr name="layout_scrollFlags">
        <flag name="scroll" value="0x1"/>
        <flag name="exitUntilCollapsed" value="0x2"/>
        <flag name="enterAlways" value="0x4"/> 
        <flag name="enterAlwaysCollapsed" value="0x8"/>
        <flag name="snap" value="0x10"/>

我已将此添加到 gradle 文件中:

compile 'com.android.support:cardview-v7:24.2.0' + '@aar'
compile 'com.android.support:recyclerview-v7:24.2.0' + '@aar'
compile 'com.android.support:appcompat-v7:24.2.0'
compile 'com.android.support:design:24.2.0'

【问题讨论】:

  • 尝试删除@aar
  • 看不到任何连接,但我还是删除并检查了。这不是问题
  • 将您收到此错误的 layout.xml 放入其中
  • 您的问题解决了吗?我也遇到同样的问题,能分享一下你是怎么解决的吗?
  • 我将支持库更改为旧版本(所有这些都有效)。最近换了新版本,运行没有问题。

标签: android gradle android-appcompat android-support-design


【解决方案1】:

当应用程序中存在同一库的不同版本时,就会出现此问题。在这种情况下,不同版本的支持库。

如果您在 gradle 文件中没有看到它们,那么它们可能是作为依赖项添加的。在终端中运行以下命令,查看每个库的依赖关系:

./gradlew app:dependencies

然后,找到使用旧版本 appcompat 的库并更新/删除任何适合您的库。

【讨论】:

    【解决方案2】:

    你的属性名和其他控件一样,修改你的自定义控件的属性名

    <declare-styleable name="MyBgView">
            <attr name="textString" format="string" />
            <attr name="textSizes" format="dimension" />
            <attr name="triangleSize" format="dimension" />
            <attr name="backgrounds" format="color" />
            <attr name="textColors" format="color" />
    

    【讨论】:

      【解决方案3】:

      Android sdk 不避免扩展属性。使用父命名空间

      <declare-styleable name="AppBarLayout_Layout" parent="AppBarLayout_LayoutParams">
          <attr name="layout_scrollFlags">
      </declare-styleable>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多