如何为不同的产品口味定义不同的依赖关系 [英] How to define different dependencies for different product flavors

查看:25
本文介绍了如何为不同的产品口味定义不同的依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将我的一个应用程序转换为 Gradle,并希望使用新的构建风格功能来获得付费和免费的基于广告的风格.

I am converting one of my apps to Gradle and would like to use the new build flavor features to have a paid and a free ad based flavor.

我只希望基于广告的版本依赖于 admob SDK.

I want only the ad based version to depend on the admob SDK.

我的构建文件如下所示:

My build file looks like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 18
    }

    productFlavors {
        Pro {
            packageName "de.janusz.journeyman.zinsrechner.pro"
        }
        Free { 
            dependencies {

            }
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
    compile fileTree(dir: 'libs', include: '*.jar')
}

有没有办法将免费产品风味中的依赖项配置为拥有自己的 libs 文件夹,该文件夹与包含两种风味的通用库的主 libs 文件夹合并?

Is there a way to configure the dependency in the free product flavor to have its own libs folder that is merged with the main libs folder that contains general libraries for both flavors?

如果可以,我将如何定义这个文件夹?

If this is possible how would I define this folder?

推荐答案

要定义特定于风味的依赖项,您可以在依赖项部分使用 proCompile 而不是 compile.当您运行 gradle 属性时,您将获得自动创建配置的概览.

To define a flavor specific dependency you can use proCompile instead of compile in your dependency section. When you run gradle properties you get an overview of automatic created configurations.

正确的构建文件如下所示:

The correct build file looks like this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}
apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 22
    }

    productFlavors {
        pro {
            packageName "de.janusz.journeyman.zinsrechner.pro"
        }
        free { }
    }
}

dependencies {
    compile 'com.android.support:support-v4:22.2.0'
    freeCompile 'com.google.android.gms:play-services-ads:7.5.0'
}

这篇关于如何为不同的产品口味定义不同的依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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