特定 gradle 风味组合的配置 [英] Config for specific gradle flavor combination

查看:43
本文介绍了特定 gradle 风味组合的配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以为特定风味组组合提供文件或配置设置.例如,我有 2 个口味组,每个有 2 种不同的口味:

I am wondering if it is possible to supply files or configuration settings for a specific flavor group combination. For example, I have 2 flavor groups, with 2 different flavors each:

风味组:版本

  • v2
  • v3

风味组:类型

  • 免费

订购类型"、版本"后,我可以构建 4 种不同风格的应用:

When ordered "Type", "Version" I am able to build 4 different flavors of my app:

  • FreeV2
  • FreeV3
  • FullV2
  • FullV3

我的源代码树看起来像这样:

And my source tree looks like this:

/src
    /free
        /res
    /full
        /res
    /v2
        /java
        /res
        AndroidManifest.xml (features and permissions for v2 flavors)
    /v3
        /java
        /res
        AndroidManifest.xml (features and permissions for v3 flavors)

这正是我想要的,并且非常适合我的项目.但是,我希望我可以提供特定风味组组合的文件.例如,我想为 FullV3 和 FullV2 提供不同的 AndroidManifest.我不认为这是可能的,或者?例如:

This is exactly what I want, and works very well for my project. However, I wish I could provide files for a specific flavor group combination. For example, I want to provide different AndroidManifests for FullV3 and FullV2. I don't think this is possible, or? For example:

/src
    /free
        /res
    /full
        /res
    /v2
        /java
        /res
        AndroidManifest.xml (features and permissions for v2 flavors)
    /v3
        /java
        /res
        AndroidManifest.xml (features and permissions for v3 flavors)
    /fullv3
        AndroidManifest.xml (features and permissions for full v3 only!)
    /fullv2
        AndroidManifest.xml (features and permissions for full v2 only!)

我也很高兴能够在 gradle 构建文件中执行此操作:

I would be nice to be able to do this in the gradle build file as well:

productFlavors {
    free {
        packageName ...
        flavorGroup "type"
    }
    full {
        packageName ...
        flavorGroup "type"
    }
    v2 {
        packageName ...
        flavorGroup "version"
    }
    v3 {
        packageName ...
        flavorGroup "version"
    }
    fullv2 {
        ...  <-- specifically for the full-v2 combination
    }
    fullv3 {
        ...  <-- specifically for the full-v3 combination
    }
}

注意:一种解决方案是只有 1 个风味组并明确定义 4 种风味:

Note: one solution would be to only have 1 flavor group and define the 4 flavors explicitly:

  • freeV2
  • freeV3
  • fullV2
  • fullV3

然而,这对我来说不是一个可行的解决方案,因为我必须为每个版本的免费和完整版本复制所有版本特定的代码.

However, this is not a viable solution for me since I would have to duplicate all the version specific code for the free and full flavors of each version.

推荐答案

此功能是在 Gradle 的 Android 插件

This functionality was added in version 0.7.0 of the Android plugin for Gradle

http://tools.android.com/tech-docs/new-构建系统 <--截至 2014 年 1 月 6 日,此链接处于活动状态

如果您有口味,您现在可以拥有一个特定于变体的源文件夹.

You can now have a variant specific source folder if you have flavors.

  • 仅适用于应用(不是库或测试).名称为 src/flavorDebug/...src/flavor1Flavor2Debug/
    • 注意驼峰命名法,首字母小写.
    • 请注意,这是针对所有维度的所有组合.
    • 其优先级高于单一风味源集,但低于构建类型.

    2014 年 1 月 30 日更新

    IntelliJ IDEA v13.0.2(内部版本 133.696)现在支持 Android Gradle 插件在 0.7.0 中所做的更改

    IntelliJ IDEA v13.0.2 (Build 133.696) now supports Android Gradle Plugin changes made in 0.7.0

    这篇关于特定 gradle 风味组合的配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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