android – 特定gradle风味组合的配置

前端之家收集整理的这篇文章主要介绍了android – 特定gradle风味组合的配置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道是否可以为特定的风味组组合提供文件或配置设置.例如,我有2个风味组,每组有2种不同的风味:

风味组:版本

> v2
> v3

风味组:类型

>免费
>满满的

订购“类型”,“版本”时,我可以构建我的应用程序的4种不同风格:

> FreeV2
> FreeV3
> FullV2
> FullV3

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

/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提供不同的AndroidManifests.我不认为这是可能的,或者?例如:

/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构建文件中执行此操作:

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个flavor组并明确定义4种flavor:

> freeV2
> freeV3
> fullV2
> fullV3

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

解决方法

功能已在 Android plugin for Gradle版本0.7.0中添加

http://tools.android.com/tech-docs/new-build-system< - 截至2014年1月6日,该链接有效

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

  • Only for app (not library or test). Name is src/flavorDebug/... or src/flavor1Flavor2Debug/
    • Note the camelcase naming,with lower case for first letter.
  • Its components (res,manifest,etc…) have higher priority than components from build type or flavors.
  • There is also a “flavor combination” source folder available when more than one flavor dimension is used. For instance src/flavor1Flavor2/
    • Note that this is for all combinations of all dimensions.
    • Its priority is higher than single-flavor sourcesets,but lower than build-types.

2014年1月30日更新

IntelliJ IDEA v13.0.2(Build 133.696)现在支持在0.7.0中进行的Android Gradle Plugin更改

猜你在找的Android相关文章