This is a pretty simple issue, but I’ve seen many questions and bad solutions about it.
An example of doing that could be:
file: app/build.gradle
android{
buildTypes{
release{
buildConfigField "int", "SAMPLE_INT", "52"
buildConfigField "boolean", "SAMPLE_BOOL", "true"
buildConfigField "String", "SAMPLE_STR", "\"release_foo\""
}
debug{
buildConfigField "int", "SAMPLE_INT", "55"
buildConfigField "boolean", "SAMPLE_BOOL", "false"
buildConfigField "String", "SAMPLE_STR", "\"debug_foo\""
}
}
}
file: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState){
String gradleStr = BuildConfig.SAMPLE_STRING;
int gradleInt = BuildConfig.SAMPLE_INT;
boolean gradleBool = BuildConfig.SAMPLE_BOOL;
}
As simple as that 🙂
hope it helps for you!