设计支持库 - SDK v21使用的版本

Mat*_*reu 20 android android-support-library android-design-library android-support-design

我有问题了解支持库的版本方案以及何时使用哪个版本.目前我有一个项目compileSdkVersion 21,minSdkVersion 21并且targetSdkVersion 21想要使用android设计支持库.当我使用com.android.support:design:22.2.0项目编译但我收到Gradle警告时:

"This support library should not use a different version (22) than the `compileSdkVersion` (21)". 
Run Code Online (Sandbox Code Playgroud)

当我使用时,com.android.support:design:23.0.1我得到一些编译错误,如:

"Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.
Run Code Online (Sandbox Code Playgroud)

我想我总是可以使用最高版本的支持库,只要compileSdkVersion它更低或相等,但这似乎是错误的.

在针对API级别21进行编译时,我可以使用设计支持库吗?

phx*_*wke 31

支持库应该始终匹配compileSdkVersion即使是targetSdkVersionminSdkVersion更低.如果要使用设计库,则需要设置compileSdkVersion为至少22和库版本22.2.0.

原因很简单.该库的版本反映了针对它构建的Android sdk的版本.如果您尝试使用支持库的更高级别版本,compileSdkVersion则可能找不到在更高版本中添加的资源.


Gab*_*tti 19

您可以使用以下方法之一:

//You have to use compileSdkVersion=22
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:design:22.2.1'

//You have to use compileSdkVersion=23
compile 'com.android.support:design:23.3.0'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:design:23.2.0'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:design:23.1.0'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:design:23.0.0'
Run Code Online (Sandbox Code Playgroud)

设计库与appcompat-v7库有依赖关系.
不能使用与api 22编译的v23.0.x版本(这是原因"Error:(2) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Inverse'.

另外,因为设计库的第一个版本是22,所以不能使用 compileSdk = 21.