【问题标题】:Error Compiling Project in Android Studio [duplicate]Android Studio中的错误编译项目[重复]
【发布时间】:2014-11-27 14:00:50
【问题描述】:

我无法在 android studio 中编译项目。出现如下所示的 4 个错误。

我的包含错误的 xml 文件是:

<style name="Theme.Bootstrap.Dark" parent="@style/Theme.AppCompat">
    <item name="android:windowBackground">@color/pager_background</item>
    <item name="actionBarStyle">@style/Widget.Styled.ActionBar</item>
    <item name="android:actionBarStyle">@style/Widget.Styled.ActionBar</item>
</style>

<style name="Widget.Styled.ActionBar" parent="@style/Widget.AppCompat.ActionBar.Solid">
    <item name="background">@drawable/actionbar_background</item>
    <item name="android:background">@drawable/actionbar_background</item>
</style>

错误是:

Error:(5, -1) android-apt-compiler: [main] D:\android\tinynote\app\src\main\res\values\theme.xml:5: error: Error retrieving parent for item: No resource found that matches the given name '@style/Theme.AppCompat'.

Error:(7, -1) android-apt-compiler: [main] D:\android\tinynote\app\src\main\res\values\theme.xml:7: error: Error: No resource found that matches the given name: attr 'actionBarStyle'.

Error:(11, -1) android-apt-compiler: [main] D:\android\tinynote\app\src\main\res\values\theme.xml:11: error: Error retrieving parent for item: No resource found that matches the given name '@style/Widget.AppCompat.ActionBar.Solid'.

Error:(12, -1) android-apt-compiler: [main] D:\android\tinynote\app\src\main\res\values\theme.xml:12: error: Error: No resource found that matches the given name: attr 'background'.

我需要修改一个基于 IntelliJ 构建的项目。我已经在 Android-Studio 中导入了它,但我无法编译它。之前构建的项目运行良好。 请通过提供一些分步解决方案来提供帮助。我现在被困在这 4 小时了。非常感谢您的帮助。

【问题讨论】:

  • 你的 build.gradle 的依赖部分有 appcompat 库吗?
  • @Tanis7x 我的 build.gradle 文件中有此代码:dependencies { compile 'com.android.support:appcompat-v7:20.+' }。你能提出什么问题吗?谢谢。
  • 查看我编辑的答案
  • @GabrieleMariotti 对不起,先生,没有什么对我有用。一个简单的错误已经破坏了我的项目。
  • 您是否在模块内部使用 build.gradle(不是顶级文件)?尝试清理,清理缓存并重建prj

标签: android xml intellij-idea android-studio android-gradle-plugin


【解决方案1】:

您很可能缺少支持目录中的AppCompat 库。AppCompat 是一个库项目。您需要在您的android项目中引用库项目。使用此链接添加您的支持包link to add app compat

您正在使用这个parent="@style/Theme.AppCompat" 而不是使用这个parent="@android:style/Theme.AppCompat"。我猜他们在文档文件中有错字

【讨论】:

  • 我做到了。在 build.gradle 中添加了依赖项。还有什么要做的吗? AppCompat 需要添加到其他任何地方吗?
  • 是的,去你的 sdk manager 看看是否安装了 Android Support Repository
  • 我已经安装了它。它就在那里。
  • 使用这个编译“com.android.support:support-v4:18.0.+”
  • 在 build.gradle 中对吗?我用这个编译。还是4个错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多