android tutorial - Flavor constants and resources in build gradle in android | Developer android - android app development - android studio - android app developement



You can use gradle to have BuildConfig constants and res values on a per flavor basis. Just add the value to the flavor you want to support.

android {
    defaultConfig {
        resValue "string", "app_name", "Full App"
        buildConfigField "boolean", "isDemo", "false"
    }
    productFlavors {
        demo {
            resValue "String", "app_name", "Demo App"
            buildConfigField "boolean", "isDemo", "true"
        }
        full {
            // use default values
        }
    }
}
click below button to copy code from our android learning website - android tutorial - team

Gradle will do all the merging / overriding for you. The generated code will also allow you to see where the values come from, e.g.

<!-- Values from default config. -->
<string name="app_name" translatable="false">Default Name</string>
click below button to copy code from our android learning website - android tutorial - team

and

public final class BuildConfig {
    public static final String VERSION_NAME = "1.0";
    // Fields from product flavor: demo
    public static final boolean isDemo = true;
}
click below button to copy code from our android learning website - android tutorial - team

Related Searches to Flavor constants and resources in build gradle in android