Get product flavor or build variant in an android app

Edit: This is now done automatically starting with version 0.7 of the plugin. BuildConfig.java will contains

public static final String BUILD_TYPE = "debug";
public static final String FLAVOR = "f1Fa";
public static final String FLAVOR_group1 = "f1";
public static final String FLAVOR_group2 = "fa";

FLAVOR is the combined flavor name with all flavor dimensions/groups applied. Then each dimension is available as FLAVOR_<group name>.

Finally BUILD_TYPE contains the name of the used build type.

If you have a single flavor dimension, then you only have the FLAVOR constant.

This is the only way to do it right now.

One thing you could do is automate it. So you could do something like this:

android {
   productFlavors.whenObjectAdded { flavor ->
       flavor.buildConfig "public static final String PRODUCT_FLAVOR = \"${flavor.name}\";"
   }

   // your normal config here.
}

This way you don’t have to manually do it for each flavor.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)