如何获取当前选择在建的gradle变种?变种、gradle

2023-09-06 07:33:52 作者:说了再见忘了早归ゆ

我使用Android的工作室与RC的gradle 2.2。我在我的构建变种部分有一些变种,我可以选择我想建立哪一个。例如,一个建立匈牙利和德国。

我有我我中的gradle脚本推出像改变的基础上的味道/变量名称的一些任务。但目前对所有构建脚本迭代变种,像这样: android.applicationVariants.each {变种 - 方式>

所以我的问题是:我怎么能得到的只有从Android工作室构建变种部分和gradle这个脚本中使用它选择的变种,所以要去除循环? / p>解决方案

您可以简单地检查变量名称,只对特定的口味运行某些任务,如:

  android.applicationVariants.all {变种 - >    如果(variant.name.contains('myflavor'){        //做的东西    }} 

Gradle入门学习

I'm using Android Studio RC with gradle 2.2. I have in my build variants section a few variants and I can choose which one I want to build. For example one build for Hungary or for Germany.

I have a few tasks that I launch in my gradle script like changing the name based on the flavor/variant. But at the moment the script iterates over all the build variants like so: android.applicationVariants.each { variant ->.

So my question is: how can I get only the chosen variant from the android studio Build Variants section and use it in gradle script, so to remove the loop?

解决方案

You can simply check the variant name and only run certain tasks for specific flavors, like this:

android.applicationVariants.all { variant ->
    if (variant.name.contains('myflavor') {
        // Do stuff
    }
}