在 Android Studio 中添加全屏活动后构建错误 [英] Build errors after adding fullscreen activity in Android Studio

查看:30
本文介绍了在 Android Studio 中添加全屏活动后构建错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Android Studio 中试验我的第一个类似Hello World"的应用程序.我尝试添加一个新活动(首先通过新建 -> Android 组件,不喜欢结果,将其删除,然后通过新建 -> 活动 -> 选择的全屏活动).现在我收到这些错误:

I'm experimenting with my first "Hello World"-like application in Android Studio. I've tried to add a new activity (first via New -> Android Component, didn't like the result, deleted it, then via New -> Activity -> selected Fullscreen activity). Now I get these errors:

  Gradle: Execution failed for task ':LanguagesMemorizer:processDebugResources'.
  > Could not call IncrementalTask.taskAction() on task ':LanguagesMemorizer:processDebugResources'
  C:\...\src\main\res\values\attrs.xml
    Gradle: Attribute "buttonBarStyle" has already been defined
    Gradle: Attribute "buttonBarButtonStyle" has already been defined

我尝试在我的项目中搜索 buttonBarStyle.发现于:

I've tried searching for buttonBarStyle in my project. It was found in:

  • build 文件夹(我想我应该忽略它,不是吗?)
  • 新活动的布局文件 (style="?buttonBarStyle")
  • values\attrs.xml 本身(<declare-styleable ...> <attr name="buttonBarStyle" format="reference"/> ...)
  • values\styles.xml (<style...>...<item name="buttonBarStyle">@style/ButtonBar</item>...)
  • values-v11\styles.xml (<style...>...<item name="buttonBarStyle">?android:attr/buttonBarStyle</item>...)

所有这些都是自动生成的.我应该如何解决这个错误?

All of it was auto-generated. How should I fix this error?

更新:attrs.xml 中有一条评论说

UPDATE: There is a comment in attrs.xml which says

<!-- Declare custom theme attributes that allow changing which styles are
         used for button bars depending on the API level.
         ?android:attr/buttonBarStyle is new as of API 11 so this is
         necessary to support previous API levels. -->

所以看起来旧的 Android 需要这些属性,但我猜 API 11 声明的属性和这些手动属性之间存在某种冲突.我应该如何修复它们?

So it seems like these attributes are needed for old Androids, but so I guess there is some sort of a conflict between API 11-declared attributes and these manual attributes. How should I fix them?

推荐答案

这是因为 com.android.support:appcompat-v7:18.0.0 已经有这个属性了.因此,如果您计划使用此支持库(并且您应该),只需从您的项目 \src\main\res\values\attrs.xml 中删除此属性的声明是安全的.我猜,这个重复是因为 AndroidStudio 新的活动向导,不假设你可以使用支持库所以它自己生成所有代码.

This is because com.android.support:appcompat-v7:18.0.0 already has this attribute. So if you plan to use this support library (and you should) it is safe to just delete declaration of this attributes from your project \src\main\res\values\attrs.xml. I guess, this duplication is because AndroidStudio new activity wizard, doesn't suppose that you can use support library so it generates all code by itself.

这篇关于在 Android Studio 中添加全屏活动后构建错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆