问题描述
不幸的是,我必须支持Android 2.3,但是我想使用具有min-sdk 14(Android 4.0)的第三方ui小部件.
unfortunately I have to support Android 2.3, but I want to use a third party ui widget that has min-sdk 14 (Android 4.0).
是否可以在min-sdk 14中包含依赖项?
Is there a way to include the dependency with min-sdk 14?
在代码中,我将检查 Build.SDK_INT
以确定是否将ui小部件与min SDK 14或后备UI小部件一起使用.
In code I would check Build.SDK_INT
to determine whether to use the ui widget with min SDK 14 or a fallback UI widget.
推荐答案
不幸的是,由于您必须包括一个依赖项,因此它将始终被编译到您的项目中.
Unfortunately, since you have to include a dependency it will always be compiled into your project.
您可以将您的项目分解为单独的项目.如果您创建了类似 BaseApp
和 IceCreamSandwichApp
之类的东西,则可以为每个设置不同的 minSdkVersions
以及一组不同的依赖项.
You could break your project out into separate projects. If you created something like a BaseApp
and a IceCreamSandwichApp
you could set different minSdkVersions
for each along with a different set of dependencies.
因此您必须在应用程序中进行模块
So you would have to modules in your app:
your-app/BaseApp
和
your-app/IceCreamSandwichApp
您的gradle文件如下所示:
And your gradle files would look something like this:
your-app/settings.gradle
include ':BaseApp', ':GingerbreadApp'
您的应用/BaseApp/build.gradle
android {
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 9
compileSdkVersion 21
targetSdkVersion 21
}
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
}
您的应用程序/IceCreamSandwichApp/build.gradle
android {
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 14
compileSdkVersion 21
targetSdkVersion 21
}
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(":BaseApp")
compile 'the.third.party:lib:here:1.0.0'
}
}
这篇关于不同API级别的Gradle依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!