Generate Java Constants
android { buildTypes { debug { buildConfigField "int", "FOO", "42" buildConfigField "String", "FOO_STRING", "\"foo\"" buildConfigField "boolean", "LOG", "true" } release { buildConfigField "int", "FOO", "52" buildConfigField "String", "FOO_STRING", "\"bar\"" buildConfigField "boolean", "LOG", "false" } } }
You can access them with BuildConfig.FOO
Generate Android resources
android { buildTypes { debug{ resValue "string", "app_name", "My App Name Debug" } release { resValue "string", "app_name", "My App Name" } } }
You can access them in the usual way with @string/app_name
or R.string.app_name
String type build config fields should be declared like this:
buildConfigField "String", "SERVER_URL", "\"http://dev.myserver.com\""
References
https://stackoverflow.com/questions/17197636/is-it-possible-to-declare-a-variable-in-gradle-usable-in-java
https://stackoverflow.com/questions/30796533/how-to-generate-buildconfigfield-with-string-type