Ошибка: Тема атрибута уже определена

Я использую студию Android для создания приложения. Я использую следующие зависимости:

  1. игровые сервисы: compile 'com.google.android.gms:play-services:5.2.08'
  2. приложение боевой v7 : compile 'com.android.support:appcompat-v7:21.0.0'
  3. поддержка Cardview : compile 'com.android.support:cardview-v7:21.0.0'
  4. поддержка просмотра Recycler: 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>

comment
Пожалуйста, опубликуйте код вашего файла wallet_attrs.xml и вашего styles.xml, который находится внутри папки значений.   -  person Hirak Chhatbar    schedule 24.10.2014
comment
отредактировал вопрос выше   -  person ash    schedule 24.10.2014
comment
попробуйте обновить свою зависимость от сервисов Google Play до этого «com.google.android.gms:play-services:6.1.+».   -  person Hirak Chhatbar    schedule 24.10.2014
comment
затем убедитесь, что все ваши инструменты сборки и инструменты поддержки в диспетчере SDK обновлены или отмечены. bcoz ur xms файлы, похоже, не имеют проблем. проблема с библиотекой. поэтому обновите все в вашем диспетчере sdk, а также зависимость от службы gms, как указано выше.   -  person Hirak Chhatbar    schedule 24.10.2014


Ответы (5)


просто используйте последнюю версию (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'

тогда все работает :)

person cV2    schedule 27.10.2014
comment
У меня такая же проблема в других библиотеках, обе из declare-styleable не дублируются, версии gradle-plugin/build tool 1.0.0/20.0.0 и 0.9+/19.0.0 - person Yuki Yoshida; 25.01.2015
comment
Идеально. Продолжайте обновлять до последних доступных версий. - person vinksharma; 05.08.2015

Просто проверьте, есть ли у вас файл с именем attrs.xml. В этом файле замените следующую строку

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

с участием

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

То есть переименовать название темы. Теперь очистите проект. Это решило мою проблему.

person arunprakashpj    schedule 09.03.2015
comment
Я переименовал название «тема» в «apptheme». - person arunprakashpj; 12.03.2015
comment
Будьте здоровы! Спасибо! - person Anton Shkurenko; 04.09.2015
comment
+1 Это точное решение проблемы. Но мне интересно, что делать, когда эти конфликтующие атрибуты находятся в двух разных сторонних неизменяемых библиотеках. - person Subin Sebastian; 23.10.2015

У меня возникла такая же проблема в Eclipse после обновления контента через диспетчер SDK.

Мне пришлось полностью удалить библиотеку сервисов Google Play из рабочей области, а затем скопировать и импортировать обновленную версию следуя инструкциям здесь.

Мне не помогло обновление указанных банок - только полный свежий импорт. Это включало обновление импорта android-support-v7-appcompat.

person brandall    schedule 25.10.2014

Если вы хотите продолжать поддерживать более старые версии Android (2.3.x, 3.xx, 4.0), используйте модифицированную версию вашей библиотеки, удалив классы и ресурсы кошелька (учитывая, что вам не нужны функциональные возможности кошелька). Это позволяет избежать этой «темы» проблема с атрибутом. Я использую play-services-5.0.89.arr без проблем.

В частности, удалите com.google.android.gms.wallet.* классов и wallet_*.xml ресурсов, и все готово.

person Emmanuel Harguindey    schedule 15.02.2016

Спасибо, Хирак, как вы упомянули, ошибка была связана с зависимостью. решил это, используя следующие версии библиотеки:

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'
person ash    schedule 24.10.2014
comment
Это очень старая версия сервисов Google Play. - person Jared Burrows; 25.10.2014
comment
Да... но он начал работать... Я получаю сообщение об ошибке, если использую последнюю версию всех этих библиотек. - person ash; 27.10.2014
comment
Я не минусовал вас, но вы должны использовать: compile 'com.google.android.gms:play-services:6.1.11'. Зачем в этом случае отвечать на свой вопрос? - person Jared Burrows; 27.10.2014