不同 api 级别的 Gradle 依赖项 [英] Gradle dependencies for different api levels

查看:25
本文介绍了不同 api 级别的 Gradle 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我必须支持 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 以确定是使用带有最小 SDK 14 的 ui 小部件还是后备 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.

您可以将项目分解为单独的项目.如果您创建了类似 BaseAppIceCreamSandwichApp 的东西,您可以为每个设置不同的 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'

your-app/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 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆