您的位置:首页 > 移动开发

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

2015-12-08 14:11 615 查看
参考:http://www.apkbus.com/android-246037-1-1.html?_dsign=361a7403

错误提示:

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为

[code]<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light"></style>  
</resources>


AndroidManifest.xml文件里面

[code]android:theme="@style/AppTheme"


项目支持的最小SDK小于API 14(即Android4.0),具体表现为

AndroidManifest.xml文件里面, minSdkVersion <14,比如

[code]<uses-sdk  android:minSdkVersion="8"
      android:targetSdkVersion="23" />


项目没有导入android-support-v7-appcompat兼容包。

解决方案

第一种:

既然没有找到 Theme.AppCompat.Light 主题,那么我就不使用此主题。

此时将项目values,values-v11,values-v14目录下的styles.xml文件里面的style都改为

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

</resources>


第二种:

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

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

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


2、此时再将项目values,values-v11,values-v14目录下的styles.xml文件里面style都改为

[code]<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配置中,增添以下语句:

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


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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: