Skip to content

Instantly share code, notes, and snippets.

@bucker
Last active September 7, 2019 13:00
Show Gist options
  • Save bucker/96c8108a9ff1f54cbebd to your computer and use it in GitHub Desktop.
Save bucker/96c8108a9ff1f54cbebd to your computer and use it in GitHub Desktop.
Android - Product flavors

A product flavor defines a customized version of the application build by the project. A single project can have different flavors which change the generated application

ex: set two different flavors of your app

productFlavors {
    develop {
        applicationId "com.your.app.1"
        versionName "1.0.0"

        buildConfigField 'String', 'HOST', '"http://api.zuul.com"'
        buildConfigField 'String', 'FLAVOR', '"prod"'
        buildConfigField "boolean", "REPORT_CRASHES", "true"
    }
    product {
        applicationId "com.your.app.2"
        versionName "1.0.1"

        buildConfigField 'String', 'HOST', '"http://api.zuul.com"'
        buildConfigField 'String', 'FLAVOR', '"prod"'
        buildConfigField "boolean", "REPORT_CRASHES", "true"
    }

so you can use the BuildConfig as:

CustomAdapter adapter = new CustomAdapter.Builder()
    .setEndpoint(BuildConfig.HOST)
    .build();

Different icons per flavor

  • Create package: src/develop/res/drawable/ic_launcher.png
  • Also works with other types of resources like strings.xml, integers.xml, arrays.xml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment