android - Gradle buildType/productFlavor using unexpected buildConfigField -
given below configuration:
productflavors { normal { applicationid "com.app" } mock { applicationid "com.app.mock" } } buildtypes { debug { productflavors.normal.buildconfigfield "boolean", "mockmode", "false" productflavors.mock.buildconfigfield "boolean", "mockmode", "true" } release { productflavors.normal.buildconfigfield "boolean", "mockmode", "false" // release should never point mocks. ever. productflavors.mock.buildconfigfield "boolean", "mockmode", "false" } }
i have expected buildconfig.mockmode = true;
, however, resultant build config:
public final class buildconfig { public static final boolean debug = boolean.parseboolean("true"); public static final string application_id = "*****"; public static final string build_type = "debug"; public static final string flavor = "mock"; public static final int version_code = 1; public static final string version_name = "1.0"; // fields product flavor: mock public static final boolean mockmode = false; }
from little investigation/debugging, realised if change value product flavour in release buildtype updates buildconfig.mockmode
value, despite having mockdebug
selected build variant.
i have better solution achieving want do, i'm looking answer helps me understand why gradle acting in way based on configuration, me understand more of doing.
you extract logic decide on actual value of buildconfig field method of own. way, dsl configuration has single line. looks (not tested - expect syntax errors):
buildtypes { applicationvariants.all { variant -> variant.buildconfigfield "boolean", "mockmode", mockmode(variant) } } def mockmode(variant) { //return true or false depending on variant.buildtype , variant.productflavors }
Comments
Post a Comment