# Get current flavor in Android Gradle

DevFeed: [Get current flavor in Android Gradle](<https://devfeed.tech/articles/get-current-flavor-in-android-gradle-25847.md>)

Original publisher: [Read original article](<https://medium.com/@banmarkovic/get-current-flavor-in-android-gradle-6d23d27259e3?source=rss-8aced922ece------2>)

Author: Ban Markovic

Published: 2023-08-07T12:20:20Z

Content type: tutorial

Language: en

Sources: [Stories by Ban Markovic on Medium](<https://devfeed.tech/sources/stories-by-ban-markovic-on-medium.md>)

Topics: [Gradle](<https://devfeed.tech/topics/gradle.md>), [Android](<https://devfeed.tech/topics/android.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [configuration](<https://devfeed.tech/topics/configuration.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [androiddev](<https://devfeed.tech/tags/androiddev.md>), [apk](<https://devfeed.tech/tags/apk.md>), [assemble](<https://devfeed.tech/tags/assemble.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [groovy](<https://devfeed.tech/tags/groovy.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [programming](<https://devfeed.tech/tags/programming.md>)

## AI overview

This tutorial explains how Android product flavors support multiple app variants from one codebase and how to identify the selected flavor in Gradle scripts. It focuses on a Kotlin DSL implementation of a getCurrentFlavor function and mentions a Groovy version.

## Source excerpt

Gradle is a topic that most Android developers postpone to learn as much as they can. This happens until we realize that it is a crucial part when it comes to packaging our apps or SDKs (here is my article that can help you out with understanding Gradle better). Since the diversity of Android devices is huge, we always need to strive not to package unnecessary things. Product flavors Sometimes it is required from us to publish different versions of our app, depending on the different requirements of our clients. This leads us to having one codebase that can support multiple configuration changes (enabling or disabling particular features) depending on our clients. To avoid changing our code each time we want to publish a different version of our app, we use product flavors. They enable us to set up different app variants at project level, and then we can reference them in our code, in order to enable or disable something. Problem Enabling or disabling particular features inside our Kotlin code is not that complex, but in order to follow those toggles, sometimes we would also like to include or exclude some plugins or libraries. Since this type of work is done in Gradle, there is a need for us to know which product flavor is selected in our Gradle file. Solution Writing Gradle scripts can be done with Kotlin DSL or Groovy, and since we already know Kotlin, I will focus on explaining the Kotlin DSL solution and later on I will also provide the full Groovy version of our getCurrentFlavor function. By using Kotlin DSL in our Gradle scripts, we can add any function at the bottom of our app/build.gradle.kts file, so let's create our getCurrentFlavor() function that returns an empty String. fun getCurrentFlavor(): String { return "" } Since we are inside our build.gradle.kts file, we have a reference to a Gradle object that belongs to our project. Inside it, we have the information of the parameters that the Gradle object uses for starting the build. By having that informa