不幸的是,由于您必须包含一个依赖项,它总是会编译到您的项目中。
您可以将项目拆分为单独的项目。如果您创建了 BaseApp 和 IceCreamSandwichApp 之类的东西,您可以为每个设置不同的 minSdkVersions 以及一组不同的依赖项。
所以你必须在你的应用程序中添加模块:
your-app/BaseApp
和
your-app/IceCreamSandwichApp
你的 gradle 文件看起来像这样:
your-app/settings.gradle
include ':BaseApp', ':GingerbreadApp'
your-app/BaseApp/build.gradle
android {
buildToolsVersion '22.0.1'
defaultConfig {
minSdkVersion 9
compileSdkVersion 21
targetSdkVersion 21
}
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
}
your-app/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'
}
}