如何在gradle中获取当前选择的构建变体? [英] How to get the currently chose build variant in gradle?

查看:126
本文介绍了如何在gradle中获取当前选择的构建变体?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 gradle 2.2 的 Android Studio RC.我在我的构建变体部分有几个变体,我可以选择我想要构建的一个.例如,为匈牙利或德国构建了一个版本.

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.

我在 gradle 脚本中启动了一些任务,例如根据风格/变体更改名称.但目前脚本遍历所有构建变体,如下所示:android.applicationVariants.each { 变体 ->.

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 ->.

所以我的问题是:我怎样才能只从 android studio Build Variants 部分获取所选的变体并在 gradle 脚本中使用它,以便删除循环?

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
    }
}

这篇关于如何在gradle中获取当前选择的构建变体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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