转载请标明出处:http://blog.youkuaiyun.com/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
- 1
- 2
- 3
错误示例分析
如果使用下面这些配置,那么就会出现上面说的错误:
- 项目使用的是Theme.AppCompat主题,具体表现为
项目values目录styles.xml文件里面style为
<resources> <style name="AppTheme" parent="Theme.AppCompat.Light"></style> </resources>
- 1
- 2
- 3
- AndroidManifest.xml文件里面
android:theme="@style/AppTheme"
- 1
- 项目支持的最小SDK小于API 14(即Android4.0)比如
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="23" />
- 1
- 2
- 项目没有导入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>
- 1
- 2
- 3
- 4
第二种:
如果没有找到 Theme.AppCompat.Light 主题,而我们又想要使用最新的主题效果呢?
1、 将AndroidManifest.xml文件里面, minSdkVersion改成14,比如
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23" />
- 1
- 2
- 3
2、此时再将项目values,values-v11,values-v14目录下的styles.xml文件里面style都改为Holo设计风格,Holo是在API 14 才推出的
<resources> <style name="AppTheme" parent="android:Theme.Holo.Light"></style></resources>
- 1
- 2
- 3
第三种:
最好的方法就是导入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}
- 1
- 2
- 3
每个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
关注我的公众号,轻松了解和学习更多技术
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.youkuaiyun.com/jiangjunshow