天天看點

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\\aapt.exe'' finished with non-zero exit value 
           

錯誤示例分析

如果使用下面這些配置,那麼就會出現上面說的錯誤:

  • 項目使用的是Theme.AppCompat主題,具體表現為

    項目values目錄styles.xml檔案裡面style為

<resources>
  <style name="AppTheme" parent="Theme.AppCompat.Light"></style>  
</resources>
           
  • AndroidManifest.xml檔案裡面
  • 項目支援的最小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。

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

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

關注我的公衆号,輕松了解和學習更多技術
No resource found that matches the given name '@style/Theme.AppCompat.Light'

繼續閱讀