我无法理解支持库的版本方案以及何时使用哪个版本。目前我有一个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)".
当我使用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编译时,我可以使用设计支持库吗?
答案 0 :(得分:30)
即使ui-router
或compileSdkVersion
较低,支持库也应始终与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.