1. 程式人生 > >解決support包引起的AndroidStudio編譯報錯

解決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版本。