【问题标题】:Error:Attribute "theme" has already been defined错误:属性“主题”已被定义
【发布时间】:2014-12-20 05:00:09
【问题描述】:

我正在使用 Android Studio 构建应用程序。我正在使用以下依赖项:

  1. 播放服务:compile 'com.google.android.gms:play-services:5.2.08'
  2. 应用实战v7:compile 'com.android.support:appcompat-v7:21.0.0'
  3. 支持卡片浏览:compile 'com.android.support:cardview-v7:21.0.0'
  4. 支持回收站视图:compile 'com.android.support:recyclerview-v7:21.0.0'

我在构建我的应用程序时遇到以下错误:

app/build/intermediates/exploded-aar/com.google.android.gms/play-services/5.2.08/res/values/wallet_attrs.xml
    Error:Attribute "theme" has already been defined

代码样式.xml

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
    </style>

</resources>

代码 wallet_attrs.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2014 Google Inc. All Rights Reserved. -->
<resources>
    <!-- Attributes for the WalletFragment &lt;fragment&gt; tag -->
    <declare-styleable name="WalletFragmentOptions">
        <!-- Theme to be used for the Wallet selector -->
        <attr name="theme" format="enum">
            <enum name="holo_dark" value="0"/>
            <enum name="holo_light" value="1"/>
        </attr>
        <!-- Google Wallet environment to use -->
        <attr name="environment" format="enum">
            <enum name="production" value="1"/>
            <enum name="sandbox" value="0"/>
            <enum name="strict_sandbox" value="2"/>
        </attr>
        <!-- A style resource specifing attributes to customize the look and feel of WalletFragment -->
        <attr name="fragmentStyle" format="reference"/>
        <!-- Fragment mode -->
        <attr name="fragmentMode" format="enum">
            <enum name="buyButton" value="1"/>
            <enum name="selectionDetails" value="2"/>
        </attr>
    </declare-styleable>

    <!-- Attributes that may be specified in a style resource to customize the look and feel of
         WalletFragment -->
    <declare-styleable name="WalletFragmentStyle">
        <!-- Height of the buy button. This includes an 8dp padding (4dp on each side) used for
             pressed and focused states of the button. The value can be a specific height, e.g.
             "48dp", or special values "match_parent" and "wrap_content". -->
        <attr name="buyButtonHeight" format="dimension">
            <enum name="match_parent" value="-1" />
            <enum name="wrap_content" value="-2" />
        </attr>
        <!-- Width of the buy button. This includes an 8dp padding (4dp on each side) used for
             pressed and focused states of the button. The value can be a specific width, e.g.
             "300dp", or special values "match_parent" and "wrap_content". -->
        <attr name="buyButtonWidth" format="dimension">
            <enum name="match_parent" value="-1" />
            <enum name="wrap_content" value="-2" />
        </attr>
        <!-- Text on the buy button. Must be one of "buy_with_google", "buy_now" and "book_now" -->
        <attr name="buyButtonText" format="enum">
            <enum name="buy_with_google" value="1"/>
            <enum name="buy_now" value="2"/>
            <enum name="book_now" value="3"/>
        </attr>
        <!-- Appearance of the buy button. Must be one of "classic", "grayscale" and "monochrome" -->
        <attr name="buyButtonAppearance" format="enum">
            <enum name="classic" value="1"/>
            <enum name="grayscale" value="2"/>
            <enum name="monochrome" value="3"/>
        </attr>
        <!-- TextAppearance for masked wallet details -->
        <attr name="maskedWalletDetailsTextAppearance" format="reference"/>
        <!-- TextAppearance for headers describing masked wallet details -->
        <attr name="maskedWalletDetailsHeaderTextAppearance" format="reference"/>
        <!-- Masked wallet details background -->
        <attr name="maskedWalletDetailsBackground" format="reference|color"/>
        <!-- TextAppearance for the "Change" button in masked wallet details view -->
        <attr name="maskedWalletDetailsButtonTextAppearance" format="reference"/>
        <!-- "Change" button background in masked wallet details view -->
        <attr name="maskedWalletDetailsButtonBackground" format="reference|color"/>
        <!-- Color of the Google Wallet logo text in masked wallet details view -->
        <attr name="maskedWalletDetailsLogoTextColor" format="color"/>
        <!-- Type of the wallet logo image in masked wallet details view -->
        <attr name="maskedWalletDetailsLogoImageType" format="enum">
            <enum name="classic" value="1"/>
            <enum name="monochrome" value="2"/>
        </attr>
    </declare-styleable>
</resources>

【问题讨论】:

  • 请发布您的 wallet_attrs.xml 文件的代码和 values 文件夹中的 styles.xml
  • 编辑了上面的问题
  • 尝试将您的 google play 服务依赖升级到这个 'com.google.android.gms:play-services:6.1.+'
  • 然后确保您在 SDK 管理器中的所有构建工具和支持工具都是最新的或注意。 bcoz 你的 xms 文件似乎没有问题。问题出在图书馆。所以更新你的 sdk 管理器中的所有内容以及上面提到的 gms 服务依赖项

标签: android compiler-errors google-play-services android-theme android-recyclerview


【解决方案1】:

只使用最新的 (21)
appCompat 和
Google Play 服务库

例如:

compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.android.support:recyclerview-v7:21.0.0' 
compile 'com.android.support:cardview-v7:21.0.0'
compile 'com.google.android.gms:play-services:6.1.11'

然后一切正常:)

【讨论】:

  • 我在其他库也有同样的问题,declare-styleable 都没有重复,gradle-plugin/build 工具的版本是 1.0.0/20.0.0 和 0.9+/19.0.0跨度>
  • 完美。不断更新到最新的可用版本。
【解决方案2】:

只需检查一下,您是否有一个名为 attrs.xml 的文件。在该文件中替换以下行

 <attr name="theme" format="reference" />

 <attr name="apptheme" format="reference" />

即重命名主题名称。 现在清理项目。 这解决了我的问题。

【讨论】:

  • 我将名称“theme”重命名为“apptheme”
  • 上帝保佑你!谢谢!
  • +1 这是问题的确切解决方案。但是我想知道当这些冲突的属性在两个不同的第三方不可更改库中时该怎么办。
【解决方案3】:

通过 SDK 管理器更新内容后,我在 Eclipse 中开发时遇到了同样的问题。

我必须从 Workspace 中完全删除 Google Play Services 库,然后复制并导入更新的版本 following the instructions here

没有更新引用的 jar 对我有帮助 - 只有全新的导入。这包括更新 android-support-v7-appcompat 导入。

【讨论】:

    【解决方案4】:

    如果您想继续支持较旧的 android 版本(2.3.x、3.xx、4.0),请使用库的修改版本删除钱包类和资源(假设您不需要钱包功能。)这样可以避免这种情况“主题”属性问题。我正在使用play-services-5.0.89.arr 没有问题。

    特别是,删除 com.google.android.gms.wallet.* 类和 wallet_*.xml 资源,您就完成了。

    【讨论】:

      【解决方案5】:

      感谢 Hirak,因为您提到错误与依赖有关。使用以下版本的库解决了它:

      compile 'com.android.support:appcompat-v7:20.0.0'
      compile 'com.google.android.gms:play-services:4.+'
      compile 'com.android.support:cardview-v7:21.0.0'
      compile 'com.android.support:recyclerview-v7:21.0.0'
      

      【讨论】:

      • 那是很老的 Google Play 服务版本
      • 是的......但它开始工作......如果我使用所有这些库的最新版本,我会收到错误。
      • 我没有对你投反对票,但你应该使用:compile 'com.google.android.gms:play-services:6.1.11'。为什么要在这种情况下回答您自己的问题?
      猜你喜欢
      • 1970-01-01
      • 2016-09-14
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      相关资源
      最近更新 更多