Android-apt-compiler:[]错误:检索项目的父项时出错:找不到与给定名称匹配的资源''

时间:2016-05-14 14:19:39

标签: android android-theme

我打开了一个在Android Studio 2.1 Beta 2中运行良好的现有项目,我在运行项目时遇到了一些错误。

样式字段是:

<style name="AppBaseTheme" parent="@android:style/Theme.AppCompat.Light">
    <!--
    Theme customizations available in newer API levels can go in
    res/values-vXX/styles.xml, while customizations related to
    backward-compatibility can go here.
    -->
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="AppBaseTheme" parent="@android:style/Theme.AppCompat.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

<style name="AppBaseTheme" parent="@android:style/Theme.AppCompat.Light">
    <!-- API 14 theme customizations can go here. -->
</style>

AndroidManifest.xml我有这样的主题的参考:

 <application
  android:theme="@style/AppTheme" >

错误是:

  

错误:(7,-1)android-apt-compiler:[mobile]   C:\ mobile \ trunk \ res \ values \ styles.xml:7:错误:检索错误   item的父级:找不到与给定名称匹配的资源   &#39; @android:风格/ Theme.AppCompat.Light&#39;

     

错误:(7,-1)android-apt-compiler:[mobile] C:\ mobile \ trunk \ res \ values-v11 \ styles.xml:7:错误:检索错误   item的父级:找不到与给定名称匹配的资源   &#39; @风格/ Theme.AppCompat.Light&#39;

     

错误:(8,-1)android-apt-compiler:[mobile] C:\ mobile \ trunk \ res \ values-v14 \ styles.xml:8:错误:检索错误   item的父级:找不到与给定名称匹配的资源   &#39; @风格/ Theme.AppCompat.Light&#39;

我尝试了几种方法来解决这个错误,但没有成功。请帮助我。

2 个答案:

答案 0 :(得分:0)

这些样式实际上来自AppCompat支持库,我假设它们属于您的gradle依赖项。

尝试将主题样式声明更改为

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
</style>

<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!-- API 11 theme customizations can go here. -->
</style>

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    <!-- API 14 theme customizations can go here. -->
</style>

在处理工作室升级时也是如此:

  • 运行&gt; gradle&gt;使用任务clean
  • 运行
  • 文件&gt;无效缓存/重新启动 - &gt;使缓存和重新启动无效
  • 制作项目

它将抛弃所有旧的构建和工件,并执行干净的构建而不是增量。有时资源不同步,这解决了它。

答案 1 :(得分:0)

我找到了解决我错误的方法。 我在ProjectStructure-&gt; Modules-&gt; MyProjectName - &gt;添加依赖项中添加了android-support-v7-appcompat的正确依赖项。 现在工作正常。