解决support包引起的AndroidStudio编译报错

有时我们在引用support包的时候会遇到下面的错误,

AGPBI: {"kind":"error","text":"error: resource android:attr/colorError not found.","sources":[{"file":"C:\\Users\\qwe\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.0.0.aar\\e789b9218a563087f526e1e34511490a\\res\\values-v26\\values-v26.xml","position":{"startLine":8,"startColumn":4,"startOffset":431,"endLine":11,"endColumn":12,"endOffset":652}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/colorError not found.","sources":[{"file":"C:\\Users\\qwe\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.0.0.aar\\e789b9218a563087f526e1e34511490a\\res\\values-v26\\values-v26.xml","position":{"startLine":12,"startColumn":4,"startOffset":657,"endLine":15,"endColumn":12,"endOffset":891}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: style attribute \u0027android:attr/keyboardNavigationCluster\u0027 not found.","sources":[{"file":"C:\\Users\\qwe\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.0.0.aar\\e789b9218a563087f526e1e34511490a\\res\\values-v26\\values-v26.xml","position":{"startLine":16,"startColumn":4,"startOffset":896,"endColumn":92,"endOffset":984}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/fontStyle not found.","sources":[{"file":"C:\\Users\\qwe\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.0.0.aar\\e789b9218a563087f526e1e34511490a\\res\\values\\values.xml","position":{"startLine":251,"startColumn":4,"startOffset":27028,"endColumn":68,"endOffset":27092}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/font not found.","sources":[{"file":"C:\\Users\\qwe\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.0.0.aar\\e789b9218a563087f526e1e34511490a\\res\\values\\values.xml","position":{"startLine":251,"startColumn":4,"startOffset":27028,"endColumn":68,"endOffset":27092}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/fontWeight not found.","sources":[{"file":"C:\\Users\\qwe\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-27.0.0.aar\\e789b9218a563087f526e1e34511490a\\res\\values\\values.xml","position":{"startLine":251,"startColumn":4,"startOffset":27028,"endColumn":68,"endOffset":27092}}],"original":"","tool":"AAPT"}
:app:processDebugResources
error: failed linking references.
:app:processDebugResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to process resources, see aapt output above for details.

{"kind":"error","text":"error: resource android:attr/colorError not found."

{"kind":"error","text":"error: resource android:attr/font not found."

* What went wrong:
Execution failed for task ':app:processDebugResources'.
> Failed to process resources, see aapt output above for details.

报各种资源找不到的错!!!

 

原因是

compileSdkVersion 25

低于

implementation 'com.android.support:appcompat-v7:27.0.0'

sdk编译版本低于support包的版本一般就会报这个错,当然并不是绝对的,一般是高版本的support包中的资源文件在底版本sdk中找不到的时候才会报错。

比如你compileSdkVerion 26,support版本用27.0.0的时候就不会报错。

但是如果你打开app下的build.gradle发现上述两个版本号一致,怎么也报错了,那你这个工程中肯定还有其他module,在其他module中引用了比主app中compileSdkVerion高的support包了

Studio在打包的时候会检测所有module中的support包,对于不同版本的情况,最终取最高版本的support包来为所有module进行编译。

原因知道了,解决办法就简单了,要么升sdk版本,要么降support版本。

你可能感兴趣的:(Android,AndroidStudio,support,appcompat,Failed,to,process,resources)