gradle - Get product flavor or build variant in an android app -
i have android app number of different product flavors configured in build.gradle file eg
productflavors { someflavor {} anotherflavor {} }
in application code, want able hold of name of compiled flavor (or build variant). 1 solution this:
productflavors { someflavor { buildconfig "public static final string product_flavor = \"someflavor\";" } anotherflavor { buildconfig "public static final string product_flavor = \"anotherflavor\";" } }
and in android app call buildconfig.product_flavor
.
is there way can gradle automatically? or there other api in android can use product flavor name?
edit: done automatically starting version 0.7 of plugin. buildconfig.java
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
combined flavor name flavor dimensions/groups applied. each dimension available flavor_<group name>
.
finally build_type
contains name of used build type.
if have single flavor dimension, have flavor
constant.
this way right now.
one thing automate it. this:
android { productflavors.whenobjectadded { flavor -> flavor.buildconfig "public static final string product_flavor = \"${flavor.name}\";" } // normal config here. }
this way don't have manually each flavor.
Comments
Post a Comment