Android Lollipop AppCompat-v7 21 - 属性“主题”已经定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26432123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:24:56  来源:igfitidea点击:

Lollipop AppCompat-v7 21 - Attribute "theme" has already been defined

androidandroid-5.0-lollipop

提问by user3184899

I wanted to upgrade my project to support Android Lollipop and API 21, so I changed AppCompat version at the dependencies to 21.0.0, and my target SDK to 21.

我想升级我的项目以支持 Android Lollipop 和 API 21,因此我将依赖项的 AppCompat 版本更改为 21.0.0,并将目标 SDK 更改为 21。

But now, When I'm trying to sync project with gradle files, it gives me 102 errorsthat weren't there before:

但是现在,当我尝试将项目与 gradle 文件同步时,它给了我102 errors以前不存在的信息:

1 error of "Attribute 'theme' has already defined"- given by my colors.XMLfile,

1 个错误"Attribute 'theme' has already defined"- 由我的colors.XML文件给出,

and another 101 errors of "no resources found that matches the given name..."- most of them are Material ones - given by "build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/values-v11/values.XML".

以及另外 101 个错误"no resources found that matches the given name..."- 其中大部分是实质性错误- 由"build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/values-v11/values.XML".

Already updated all SDK tools in Android SDK software, Using Android Studio 0.8.9 Beta.

已经更新了 Android SDK 软件中的所有 SDK 工具,使用 Android Studio 0.8.9 Beta。

Can anyone help? Thanks.

任何人都可以帮忙吗?谢谢。

回答by tilal6991

I had the first issue as well. It can be fixed by updating the Google Play Services dependency to 6.1.+.

我也遇到了第一个问题。可以通过将 Google Play 服务依赖项更新到 6.1.+ 来修复它。

In Gradle (which I hope you are using) this is: compile 'com.google.android.gms:play-services:6.1.+'

在 Gradle(我希望你正在使用)中,这是: compile 'com.google.android.gms:play-services:6.1.+'

As for the second issue - as people have said in the comments, you should make sure ALL the components in your SDK installation are up to date.

至于第二个问题 - 正如人们在评论中所说,您应该确保 SDK 安装中的所有组件都是最新的。

回答by Fedor Kazakov

I had the same problem but upgrade to latest versions doesn't helped.

我遇到了同样的问题,但升级到最新版本没有帮助。

But error message Attribute “theme” has already been definedchanged to Attribute “layout” has already been defined

但错误信息Attribute “theme” has already been defined改为Attribute “layout” has already been defined

In Google Play Services changes I've found this

在 Google Play 服务更改中,我发现了这一点

  <declare-styleable name="WalletFragmentOptions">
         <!-- Theme to be used for the Wallet selector -->
-        <attr name="theme" format="enum">
+        <attr name="appTheme" format="enum">

And this is the key.

这是关键。

If you have in your attr.xml attributes themeor layoutor maybe something else - rename it. It seems merger can't deal with it.

如果您的 attr.xml 属性中有主题布局或其他内容 - 重命名它。看来合并处理不了。

回答by Vikas

Gradle in the Android studio suggests the latest version of com.google.android.gms:play-services. After updating that to the latest version, the problem got solved.

Android Studio 中的 Gradle 建议使用最新版本的com.google.android.gms:play-services. 更新到最新版本后,问题就解决了。

compile 'com.google.android.gms:play-services:8.3.0'

编译 'com.google.android.gms:play-services:8.3.0'

回答by Murmel

For Eclipse-users:

对于 Eclipse 用户:

Because if you followed the recommandation for installing gps, you only have a copy of it in your workspace, which won't get updated.

因为如果您按照安装 gps 的建议进行操作,则您的工作区中只有它的副本,并且不会更新。

回答by Hesam

Sometimes the library you are using has this attribute. I was using Sliding up panellibrary and I got following error during build time. I had following items in my dependency libraries:

有时您使用的库具有此属性。我正在使用Sliding up panel库,但在构建期间出现以下错误。我的依赖库中有以下项目:

dependencies {
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile 'com.sothree.slidinguppanel:library:+'
    // ...
}

I fixed my problem by removing sliding library :(

我通过删除滑动库解决了我的问题:(

回答by Benjamin Piette

After adding a new activity in my project, it seems like Android Studio automatically updated my dependencies, after what that error started to appear.

在我的项目中添加新活动后,Android Studio 似乎自动更新了我的依赖项,之后该错误开始出现。

I changed the following dependencies to the latest compatibility libraries:

我将以下依赖项更改为最新的兼容性库:

compile 'com.android.support:support-v4:21.0.3'
compile 'com.android.support:appcompat-v7:21.0.3'

to the ones I had in my gradle.build before Studio edited it without asking me:

在 Studio 编辑它之前我在 gradle.build 中的那些没有问我:

compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'

Then let Studio make a Sync, and your build should work.

然后让 Studio 进行同步,您的构建应该可以工作了。