You would like to enable analytics tracking only in release builds. How can you create a new field in the generated BuildConfig class to store that value?

✅  The correct answer is:

  • buildTypes {
    debug {
    buildConfigField ‘boolean’, ‘ENABLE_ANALYTICS’, ‘false’
    }
    release {
    buildConfigField ‘boolean’, ‘ENABLE_ANALYTICS’, ‘true’
    }
    }

Question:

You would like to enable analytics tracking only in release builds. How can you create a new field in the generated BuildConfig class to store that value?

Solution:

  • buildTypes {
    debug {
    buildConfig ‘boolean’, ‘ENABLE_ANALYTICS’, ‘false’
    }
    release {
    buildConfig ‘boolean’, ‘ENABLE_ANALYTICS’, ‘true’
    }
    }
  • buildTypes {
    debug {
    buildConfig ‘String’, ‘ENABLE_ANALYTICS’, ‘false’
    }
    release {
    buildConfig ‘String’, ‘ENABLE_ANALYTICS’, ‘true’
    }
    }
  • buildTypes {
    debug {
    buildConfigField ‘boolean’, ‘ENABLE_ANALYTICS’, ‘false’
    }
    release {
    buildConfigField ‘boolean’, ‘ENABLE_ANALYTICS’, ‘true’
    }
    }
  • buildTypes {
    debug {
    buildConfigField ‘boolean’, ‘ENABLE_ANALYTICS’, ‘true’
    }
    release {
    buildConfigField ‘boolean’, ‘ENABLE_ANALYTICS’, ‘false’
    }
    }