Customize build using gradle - agileinfoways/Android-Guidelines GitHub Wiki
buildConfigField usage example
buildTypes {
release {
...
buildConfigField "boolean", "REPORT_CRASHES", "false"
buildConfigField "int", "LEVEL", "2"
buildConfigField "String", "BASE_URL", "\"http://www.testapi.com\""
}
debug {
...
buildConfigField "boolean", "REPORT_CRASHES", "true"
buildConfigField "int", "LEVEL", "1"
buildConfigField "String", "BASE_URL", "\"http://www.api.com\""
}
}
Note : Sync your project after adding above lines in app level build.gradle file. After syncing complete, you can access all these values anywhere in java file.
JAVA File Access Example
if (BuildConfig.REPORT_CRASHES) {
// enable crash reporting
}
You can define different values for debug and release app. So in above example when you select build variant as debug, the value of REPORT_CRASHES would be true which we have defined in debug{} block. When you select build variant as release, the value of REPORT_CRASHES would be false which we have defined in release{} block.