No resource found that matches the given name '@style/Theme.AppCompat.Light'

转载请标明出处:http://blog.csdn.net/xx326664162/article/details/50216627 文章出自:薛瑄的博客

你也可以查看我的其他同类文章,也会让你有一定的收货!

遇到这个问题,有时候虽然解决了,但是还是不知道原理是什么,我写了这两篇文章,或许能借你心中疑惑

原理可参考这里:Android Support兼容包详解

在了解了Support后,再来看一个实际的例子,真实感受一下,它在实战中的应用

错误提示:

No resource found that matches the given name '@style/Theme.AppCompat.Light'

Error:Execution failed for task ':app:processDebugResources'.>   com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'd:\Android\sdk\build-tools\23.0.1\aapt.exe'' finished with non-zero exit value 1

错误示例分析

如果使用下面这些配置,那么就会出现上面说的错误:

  • 项目使用的是Theme.AppCompat主题,具体表现为
    项目values目录styles.xml文件里面style为
<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light"></style>  
</resources>
  • AndroidManifest.xml文件里面
android:theme="@style/AppTheme"
  • 项目支持的最小SDK小于API 14(即Android4.0)比如
<uses-sdk  android:minSdkVersion="8"
      android:targetSdkVersion="23" />
  • 项目没有导入android-support-v7-appcompat兼容包。

解决方案

第一种:

既然没有找到 Theme.AppCompat.Light 主题,那么我就不使用此主题。
此时将项目values,values-v11,values-v14目录下的styles.xml文件里面的style都改为

<resources>
 <style name="AppTheme" parent="android:Theme.Light"></style>

</resources>

第二种:

如果没有找到 Theme.AppCompat.Light 主题,而我们又想要使用最新的主题效果呢?

1、 将AndroidManifest.xml文件里面, minSdkVersion改成14,比如

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="23" />

2、此时再将项目values,values-v11,values-v14目录下的styles.xml文件里面style都改为Holo设计风格,Holo是在API 14 才推出的

<resources>
 <style name="AppTheme" parent="android:Theme.Holo.Light"></style>
</resources>

第三种:

最好的方法就是导入android-support-v7-appcompat库。下面具体介绍:
1 、通过Android SDK Manager下载最新的Android Support Library。
这里写图片描述

2、在module的build.gradle配置中,增添以下语句:

dependencies {
    compile 'com.android.support:appcompat-v7:23.0.1
}

每个compileSdkVersion 版本都有对应的support 版本,因为support库都已经下载到了本地,可以在这个路径\sdk\extras\android\m2repository\com\android\support\ ,查看有哪些版本可以使用

compileSdkVersion 版本比support 版本低时,在上面语句处提示

This support library should not use a different version (23) than the compileSdkVersion (22) less… (Ctrl+F1)
There are some combinations of libraries, or tools and libraries, that are incompatible, or can lead to bugs. One such incompatibility is compiling with a version of the Android support libraries that is not the latest version (or in particular, a version lower than your targetSdkVersion.)

compileSdkVersion 版本比support 版本高时,在上面语句处提示

A newer version of com.android.support:appcompat-v7 than 22 is available: 23.0.1 less… (Ctrl+F1)
This detector looks for usages of libraries where the version you are using is not the current stable release. Using older versions is fine, and there are cases where you deliberately want to stick with an older version. However, you may simply not be aware that a more recent version is available, and that is what this lint check helps find.

参考:http://www.apkbus.com/android-246037-1-1.html?_dsign=361a7403

https://stackoverflow.com/questions/25471668/support-library-version

关注我的公众号,轻松了解和学习更多技术
这里写图片描述

发布了244 篇原创文章 · 获赞 799 · 访问量 234万+
展开阅读全文

新建android工程 报错,大神看过来

06-21

[2015-06-21 09:40:53 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:40:53 - HellowWord] [2015-06-21 09:40:53 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:40:53 - HellowWord] [2015-06-21 09:40:53 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 09:40:53 - HellowWord] [2015-06-21 09:40:55 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:40:55 - HellowWord] [2015-06-21 09:40:55 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:40:55 - HellowWord] [2015-06-21 09:40:55 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 09:40:55 - HellowWord] [2015-06-21 09:41:00 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:41:00 - HellowWord] [2015-06-21 09:41:00 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:41:00 - HellowWord] [2015-06-21 09:41:00 - HellowWord] F:\eclipse 32\workspace\HellowWord\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 09:41:00 - HellowWord] [2015-06-21 09:54:11 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:54:11 - HellowAndroid] [2015-06-21 09:54:11 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:54:11 - HellowAndroid] [2015-06-21 09:54:11 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 09:54:11 - HellowAndroid] [2015-06-21 09:54:13 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:54:13 - HellowAndroid] [2015-06-21 09:54:13 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:54:13 - HellowAndroid] [2015-06-21 09:54:13 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 09:54:13 - HellowAndroid] [2015-06-21 09:54:14 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:54:14 - HellowAndroid] [2015-06-21 09:54:14 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 09:54:14 - HellowAndroid] [2015-06-21 09:54:14 - HellowAndroid] F:\eclipse 32\workspace\HellowAndroid\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 09:54:14 - HellowAndroid] [2015-06-21 10:11:03 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:11:03 - HellowWorld] [2015-06-21 10:11:03 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:11:03 - HellowWorld] [2015-06-21 10:11:03 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 10:11:03 - HellowWorld] [2015-06-21 10:11:04 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:11:04 - HellowWorld] [2015-06-21 10:11:04 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:11:04 - HellowWorld] [2015-06-21 10:11:04 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 10:11:04 - HellowWorld] [2015-06-21 10:11:05 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:11:05 - HellowWorld] [2015-06-21 10:11:05 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:11:05 - HellowWorld] [2015-06-21 10:11:05 - HellowWorld] F:\eclipse 32\workspace\HellowWorld\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 10:11:05 - HellowWorld] [2015-06-21 10:46:52 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:46:52 - HellowWorld1] [2015-06-21 10:46:52 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:46:52 - HellowWorld1] [2015-06-21 10:46:52 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 10:46:52 - HellowWorld1] [2015-06-21 10:46:54 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:46:54 - HellowWorld1] [2015-06-21 10:46:54 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:46:54 - HellowWorld1] [2015-06-21 10:46:54 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 10:46:54 - HellowWorld1] [2015-06-21 10:47:05 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:47:05 - HellowWorld1] [2015-06-21 10:47:05 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values-v11\styles.xml:7: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light'. [2015-06-21 10:47:05 - HellowWorld1] [2015-06-21 10:47:05 - HellowWorld1] F:\eclipse 32\workspace\HellowWorld1\res\values-v14\styles.xml:8: error: Error retrieving parent for item: No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'. [2015-06-21 10:47:05 - HellowWorld1] 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 代码科技 设计师: Amelia_0503

分享到微信朋友圈

×

扫一扫,手机浏览