Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the build variant at runtime in Android Studio?

I'd like to get the build variant during runtime, is this possible without any extra config or code?

like image 402
tyler Avatar asked May 02 '14 15:05

tyler


People also ask

Where is build variants in Android Studio?

To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar. For projects without native/C++ code, the Build Variants panel has two columns: Module and Active Build Variant.

What is build variant in Android?

Build variants are the result of Gradle using a specific set of rules to combine settings, code, and resources configured in your build types and product flavors. Although you do not configure build variants directly, you do configure the build types and product flavors that form them.

How do I get the current build type in Gradle?

In your build. gradle (:app): tasks. all { Task task -> if (task.name == "preDebugBuild") { doFirst { //for debug build } } else if (task.name == "preReleaseBuild") { doFirst { //for release build } } } dependencies { ... }

What is build type in Gradle Android?

A build type determines how an app is packaged. By default, the Android plug-in for Gradle supports two different types of builds: debug and release . Both can be configured inside the buildTypes block inside of the module build file.


1 Answers

Look at the generated BuildConfig class.

public final class BuildConfig {   public static final boolean DEBUG = Boolean.parseBoolean("true");   public static final String APPLICATION_ID = "com.example.app";   public static final String BUILD_TYPE = "debug";   public static final String FLAVOR = "";   public static final int VERSION_CODE = 1;   public static final String VERSION_NAME = ""; } 
like image 73
ashishduh Avatar answered Oct 24 '22 00:10

ashishduh