Android工作室gradle flavor维度构建varients无法正常工作 [英] Android studio gradle flavor dimensions build varients not working correctly

查看:212
本文介绍了Android工作室gradle flavor维度构建varients无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序的两个维度,然后调用绿色和蓝色。只有这两个维度,但产品口味数量不受限制。这是我在gradle中设置它的方式。

  flavorDimensionsgreen,blue

productFlavors {

one {
applicationIdcom.app.green.one
versionCode 1
versionName1.0.0.1;
flavorDimension =green
}
two {
applicationIdcom.app.blue.two
versionCode 6
versionName1.0.1 ;
flavorDimension =blue
}
}

在我同步gradle后,在构建变体选项卡中,我看到的是oneTwoDebug和oneTwoRelease,我应该看到greenOneDebug greenOneRelease,blueTwoDebug,blueTwoRelease

就像这样

 一个{
applicationIdcom.app.green.one
versionCode 1
versionName1.0.0.1;
flavorDimension =green
}
two {
applicationIdcom.app.blue.two
versionCode 6
versionName1.0.1 ;
flavorDimension =blue
}
三个{
applicationIdcom.app.green.three
versionCode 1
versionName1.0.0.1 ;
flavorDimension =green
}
四个{
applicationIdcom.app.blue.four
versionCode 6
versionName1.0.1 ;
flavorDimension =blue
}

在这种情况下,尺寸代表类型的应用程序,然后风味更多的组织可以被添加。

**编辑我有错误的设置为gradle如在这里指出的是一个更准确地描述我所拥有的

  flavorDimensionstype,organization

productFlavors {

blue {
applicationIdcom.app.blue
flavorDimension =type
versionCode 6
versionName1.0.1;
}
red {
applicationIdcom.app.red
flavorDimension =type
versionCode 1
versionName1.0.0.1;
}

company1 {
flavorDimension =organization
}
company2 {
flavorDimension =organization
}

$ / code>

到目前为止,这可以工作,所以我可以创建用于切换类型的java源目录,但如果我想要组织特定的配置文件,我是否也为每个组织创建java源代码?

我认为你误解了flavorDimension的概念。

flavorDimension类似于风味类别,每个维度的风格的每种组合都会生成一个变体。



在您的情况下,您必须定义一个名为type的flavorDimension和另一个名为organization的维。
它将产生,对于维度组织中所有可能的类型(或双重表述:对于每个类型它将产生每个组织的变体)。

风味维度定义了将用于生成变体的<笛卡尔积> 。






编辑:我会尝试用伪gradle代码说明:



让我们定义一些类型:铜,银和金

让我们定义一些组织:customerA,customerB,customerC



所有这些都是 productFlavors ,但它们属于2个不同的维度:

<$ p $
$ b $ dimension =type_line
}
银{
...
尺寸=type_line
}
铜{b $ b ...
尺寸=type_line
}

customerA {
...
dimension =organization
}
customerB {
...
dimension =organization
}
customerC {
...
dimension =organization
}

}

这个配置会生成18个(3 * 3 * 2)变体(如果您有2个标准构建类型:调试和发布):

gold-customerA-debug; gold-customerA-release; gold-customerB-debug; gold-customerB-release; gold-customerC-debug; gold-customerC-release;

silver-customerA-debug; silver-customerA-release; silver-customerB-debug; silver-customerB-release; silver-customerC-debug; silver-customerC-release;



...(同样用于铜牌)



请注意,尺寸的名称完全是任意的对变体名称没有影响。



风味维度非常强大,但是如果您使用的风格太多:它会导致变体数量呈指数级增长后期构建清理任务可能有助于删除无用或无意义的变体)


I have two dimensions of an app, call then green and blue. There will only be these two dimensions but an unlimited number of product flavors. This is the way I'm setting it up in gradle

flavorDimensions "green", "blue"

productFlavors {

    one {
        applicationId "com.app.green.one"
        versionCode 1
        versionName "1.0.0.1";
        flavorDimension = "green"
    }
    two {
        applicationId "com.app.blue.two"
        versionCode 6
        versionName "1.0.1";
        flavorDimension = "blue"
    }
}

But then after i sync gradle, in the build variants tab all I see is oneTwoDebug and oneTwoRelease, where I should see greenOneDebug greenOneRelease, blueTwoDebug, blueTwoRelease

In theory I want to extend it to be something like this

one {
    applicationId "com.app.green.one"
    versionCode 1
    versionName "1.0.0.1";
    flavorDimension = "green"
}
two {
    applicationId "com.app.blue.two"
    versionCode 6
    versionName "1.0.1";
    flavorDimension = "blue"
}
three {
    applicationId "com.app.green.three"
    versionCode 1
    versionName "1.0.0.1";
    flavorDimension = "green"
}
four {
    applicationId "com.app.blue.four"
    versionCode 6
    versionName "1.0.1";
    flavorDimension = "blue"
}

In this case dimensions represent the "type" of app, and then the flavors are more for organizations which can be added.

**EDIT I had the wrong set up for gradle as pointed out here is a more accurate depiction of what I have

flavorDimensions "type", "organization"

productFlavors {

    blue {
        applicationId "com.app.blue"
        flavorDimension = "type"
        versionCode 6
        versionName "1.0.1";
    }
    red {
        applicationId "com.app.red"
        flavorDimension = "type"
        versionCode 1
        versionName "1.0.0.1";
    }

    company1 {
        flavorDimension = "organization"
    }
    company2 {
        flavorDimension = "organization"
    }
}

So far this works, So I can create java source directories for toggling types, but what if I want organization specific config files, do I create java source dirs for each organization as well?

解决方案

I think you misunderstood the concept of flavorDimension.

A flavorDimension is something like a flavor category and every combination of a flavor from each dimension will produce a variant.

In your case, you must define one flavorDimension named "type" and another dimension named "organization". It will produce, for each flavor in the dimension "organization" all possible "type" (or the dual formulation : for each "type" it will produce a variant for each organization).

The flavor dimensions define the cartesian product that will be used to produce variants.


EDIT : I'll try to illustrate with pseudo-gradle code:

Let's define some "type" : bronze, silver and gold

Let's define some organizations : customerA, customerB, customerC

All those are productFlavors, but they belong to 2 different dimensions:

flavorDimensions("type_line", "organization")
productFlavors {

    gold {
        ...
        dimension = "type_line"
    }
    silver {
        ...
        dimension = "type_line"
    }
    bronze {
         ...
        dimension = "type_line"
    }

     customerA {
        ...
        dimension = "organization"
    }
    customerB {
        ...
        dimension = "organization"
    }
    customerC {
         ...
        dimension = "organization"
    }

}

This config will produce 18 (3*3*2) variants (if you have the 2 standard build types : debug and release) :

gold-customerA-debug ; gold-customerA-release ; gold-customerB-debug ; gold-customerB-release ; gold-customerC-debug ; gold-customerC-release ;

silver-customerA-debug ; silver-customerA-release ; silver-customerB-debug ; silver-customerB-release ; silver-customerC-debug ; silver-customerC-release ;

... (the same for bronze)

Note that the name of the dimension is totally arbitrary and have no impact on variant names.

Flavor dimensions are very powerful, but if you use too much of them : it results in an exponential explosion of the number of variants (a post build clean-up task may be useful to delete useless or non-sense variant)

这篇关于Android工作室gradle flavor维度构建varients无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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