# Generate build using build variant in android

**URL:** <https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289>\
**Category:** Question & Answer\
**Tags:** android\
**Created:** [March 28, 2017, 8:58am UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289 "2017-03-28T08:58:59Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![usmanafzal](https://avatars.discourse-cdn.com/v4/letter/u/67e7ee/32.png) [@usmanafzal](https://discuss.bitrise.io/u/usmanafzal)\
**Post date:** [March 28, 2017, 8:58am UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/1 "2017-03-28T08:58:59Z")

</div>

I need to know how to generate build of particular build variant like I have 3 build variants

- beta
- staging
- production  
and I want to generate build for beta when beta flow is selected and staging for staging release can anyone help me out?

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [March 28, 2017, 9:45am UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/2 "2017-03-28T09:45:11Z")

</div>

Hi @usmanafzal,

Thanks for asking this here! 🙂

> [@usmanafzal](#):
>
> I need to know how to generate build of particular build variant like

You can run / specify the flavor specific Gradle Task, every flavor should have e.g. an `assembleX` task which can be run as a gradle task:

> <https://stackoverflow.com/questions/21307444/gradle-how-to-build-different-flavours-of-different-built-types/21307568#21307568>

You can set the Gradle task as the **Gradle task to run** option of the **Gradle Runner** step.

**You can get the full list of tasks you can run with gradle on your project with** : `gradle tasks`  
_( source & more info: [http://devcenter.bitrise.io/android/android-tips-and-tricks/#what-are-gradle-tasks-and-how-can-i-get-the-list-of-available-tasks-in-my-project](http://devcenter.bitrise.io/android/android-tips-and-tricks/#what-are-gradle-tasks-and-how-can-i-get-the-list-of-available-tasks-in-my-project) )_

> [@usmanafzal](#):
>
> and I want to generate build for beta when beta flow is selected and staging for staging release

Just create corresponding workflows, or use Workflow Environment Variables for beta, staging, production, … and specify the Triggers when to run which workflow: [Using the Trigger Map to trigger builds - Bitrise Docs](http://devcenter.bitrise.io/webhooks/trigger-map/)

A very minimal (not complete, only for demonstration!) example:

```auto
format_version: 1.3.1
default_step_lib_source: https://github.com/bitrise-io/bitrise-steplib.git
trigger_map:
- push_branch: master
  workflow: release
- push_branch: '*'
  workflow: beta
- pull_request_source_branch: '*'
  workflow: beta
workflows:
  beta:
    steps:
    - gradle-runner@1.5.4:
        inputs:
        - gradle_task: assembleOne
  release:
    steps:
    - gradle-runner@1.5.4:
        inputs:
        - gradle_task: assembleTwo

```

This configuration will select the `release` workflow for pushes on the `master` branch, and for pushes on any other branch and for Pull Requests it’ll select the `beta` workflow.

The beta workflow’s gradle runner step will run the `assembleOne` gradle task, while the `release` workflow’s gradle runner will run the `assembleTwo` task.

* * *

If you have any questions just let us know!  
Happy Building! 😉

---

<div class="post-metadata">

**Author:** ![Hanchul\_Kim](https://avatars.discourse-cdn.com/v4/letter/h/b2d939/32.png) [@Hanchul\_Kim](https://discuss.bitrise.io/u/Hanchul_Kim)\
**Post date:** [December 3, 2018, 5:40am UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/3 "2018-12-03T05:40:11Z")

</div>

Hi, @viktorbenei  
How can I achieve this using `Android Build` step? It provides `Variant` input, but I can succeed with only single variant. It wasn’t work splitting with `\n`, `space`. According to [this](https://github.com/bitrise-tools/go-android/blob/cad5a20e271b6a9667ca2063ec6286f51387b9e4/gradle/variant.go#L14), I think it should work with `\n`  
Here is my build log.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/9/90b8a83497fa6e42a992b210c43e4fccdb2dc6c8.png)

---

<div class="post-metadata">

**Author:** ![fehersanyi-bitrise](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/fehersanyi-bitrise/32/1912_2.png) [@fehersanyi-bitrise](https://discuss.bitrise.io/u/fehersanyi-bitrise)\
**Post date:** [December 3, 2018, 3:02pm UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/4 "2018-12-03T15:02:40Z")

</div>

Hy @Hanchul_Kim!  
I would suggest trying with two steps for the two flavours, or try the separation by single spaces.

---

<div class="post-metadata">

**Author:** ![Hanchul\_Kim](https://avatars.discourse-cdn.com/v4/letter/h/b2d939/32.png) [@Hanchul\_Kim](https://discuss.bitrise.io/u/Hanchul_Kim)\
**Post date:** [December 3, 2018, 3:22pm UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/5 "2018-12-03T15:22:58Z")

</div>

Hi, @fehersanyi-bitrise  
If so… there would be no other options, except splitting into two steps. Separation by single space doesn’t work.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/7/74b86ba1fd5f5706079268254aace29149571529.png)

---

<div class="post-metadata">

**Author:** ![bitce](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/bitce/32/1639_2.png) [@bitce](https://discuss.bitrise.io/u/bitce)\
**Post date:** [December 3, 2018, 3:28pm UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/6 "2018-12-03T15:28:05Z")

</div>

Hi @Hanchul_Kim!

Maybe I’m missing something but I’m wondering, do you lose anything by including this in two steps? It should be the same amount of build time and easier to see through since they are separated.

---

<div class="post-metadata">

**Author:** ![Hanchul\_Kim](https://avatars.discourse-cdn.com/v4/letter/h/b2d939/32.png) [@Hanchul\_Kim](https://discuss.bitrise.io/u/Hanchul_Kim)\
**Post date:** [December 3, 2018, 3:53pm UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/7 "2018-12-03T15:53:35Z")

</div>

Hi, @bitce  
Not really, but I just expected `Build Variants` not `Build Variant` in a single step. I just felt it would be better to provide multiple variants in a single step. Although it’s not a common situation, 5 variants needs 5 steps.

---

<div class="post-metadata">

**Author:** ![koral](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/koral/32/357_2.png) [@koral](https://discuss.bitrise.io/u/koral)\
**Post date:** [December 3, 2018, 5:52pm UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/8 "2018-12-03T17:52:24Z")

</div>

> [@fehersanyi-bitrise](#):
>
> or try the separation by single spaces.

It won’t work. As we can see in source code only single variant or empty input is accepted for now. [https://github.com/bitrise-steplib/bitrise-step-android-build/blob/master/main.go#L102](https://github.com/bitrise-steplib/bitrise-step-android-build/blob/master/main.go#L102)

BTW the recommended separator is `|` (pipe character): [https://github.com/bitrise-io/bitrise/blob/master/\_docs/step-development-guideline.md#inputs-which-can-accept-a-list-of-values](https://github.com/bitrise-io/bitrise/blob/master/_docs/step-development-guideline.md#inputs-which-can-accept-a-list-of-values)

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [December 4, 2018, 12:14pm UTC](https://discuss.bitrise.io/t/generate-build-using-build-variant-in-android/1289/9 "2018-12-04T12:14:51Z")

</div>

Indeed @fehersanyi-bitrise is right @Hanchul_Kim - the Android Build step only supports a single variant, but you can of course add multiple Android Builds steps.

The “old school” Gradle Runner step accepts multiple gradle tasks, so that can also be an option, but based on our past experience newer steps created by us usually focus on doing one thing at a time, similar to how most people use the related GUI options during development, this way describing what you’d do if you’d perform these manually.
