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

查看:85
本文介绍了不同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 以确定是否将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依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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