针对不同api级别的Gradle依赖性

时间:2014-11-06 18:54:30

标签: android android-studio android-gradle

不幸的是我必须支持Android 2.3,但我想使用具有min-sdk 14(Android 4.0)的第三方ui小部件。

有没有办法在min-sdk 14中包含依赖项?

在代码中,我会检查Build.SDK_INT以确定是否将ui小部件与min SDK 14或后备UI小部件一起使用。

2 个答案:

答案 0 :(得分:0)

这是不可能的......如果你有一个依赖,它就在你的编译中。在你的apk里面。您可以选择是否要将此第三方库与if(SDK_INT)一起使用,但是lib将在您的应用程序中编译。

答案 1 :(得分:0)

不幸的是,由于您必须包含依赖项,因此它将始终编译到您的项目中。

您可以将项目分解为单独的项目。如果您创建的内容类似于BaseAppIceCreamSandwichApp,则可以为每个minSdkVersions设置不同的your-app/BaseApp 以及不同的依赖项集。

所以你需要在你的应用程序中使用模块:

your-app/IceCreamSandwichApp

include ':BaseApp', ':GingerbreadApp'

你的gradle文件看起来像这样:

您应用内/ settings.gradle

android {
    buildToolsVersion '22.0.1'

    defaultConfig {
        minSdkVersion 9
        compileSdkVersion 21
        targetSdkVersion 21
    }

...

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
    }

}

您应用内/ BaseApp /的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'
    }

}

您应用内/ IceCreamSandwichApp /的build.gradle

header("Content-type: text/html");
echo "<html>This  would make mypage.php behave as an HTML</html>";
// This is usually unnecessary since text/html is already the default header

header("Content-type: text/javascript");
echo "this would make mypage.php behave as a javascript";

header("Content-type: text/css");
echo "this would make mypage.php behave as a CSS";

header('Content-type: image/jpeg');
readfile("source/to/my/file.jpg");
// this would make mypage.php display file.jpg and act as a jpg

header('Content-type: image/png');
readfile("source/to/my/file.png");
// this would make mypage.php display file.png and act as a png

header('Content-type: image/gif');
readfile("source/to/my/file.gif");
// this would make mypage.php display file.gif and act as a gif

header('Content-type: image/x-icon');
readfile("source/to/my/file.ico");
// this would make mypage.php display file.ico and act as an icon

header('Content-type: image/x-win-bitmap');
readfile("source/to/my/file.cur");
// this would make mypage.php display file.cur and act as a cursor