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

时间:2015-10-04 23:31:02

标签: android android-support-library android-design-library android-support-design

我无法理解支持库的版本方案以及何时使用哪个版本。目前我有一个compileSdkVersion 21minSdkVersion 21targetSdkVersion 21的项目,并希望使用Android设计支持库。 当我使用com.android.support:design:22.2.0项目编译时,我得到一个Gradle警告:

"This support library should not use a different version (22) than the `compileSdkVersion` (21)". 

当我使用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'.

我认为只要compileSdkVersion更低或相等,我就可以始终使用最高版本的支持库,但这似乎是错误的。

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

2 个答案:

答案 0 :(得分:30)

即使ui-routercompileSdkVersion较低,支持库也应始终与targetSdkVersion匹配。如果要使用设计库,则需要将minSdkVersion设置为至少22和库版本22.2.0。

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

答案 1 :(得分: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'

设计库与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.