I am reading config fields from an environment.properties
file that I would like to reuse in my Android application. I have tried various ways to get values from gradle's build without success (Gradle 2.7):
buildTypes {
debug {
buildConfigField "String", "SERVER_SCHEME", getBuildConfigField('SERVER_SCHEME')
buildConfigField "String", "SERVER_BASE_URL", getBuildConfigField('SERVER_BASE_URL')
buildConfigField "int", "SERVER_PORT", getBuildConfigField('SERVER_PORT')
buildConfigField "String", "SERVER_CONTEXT", getBuildConfigField('SERVER_CONTEXT')
}
}
where getBuildConfigFields(key)
is a function defined in my config.gradle
reading a file and returning the value corresponding to the specified key.
I have tried :
buildConfigField "TYPE" "KEY" "VALUE"
,buildConfigField("TYPE" "KEY" "VALUE")
resValue "TYPE" "KEY" "VALUE"
But none of the are working with gradle errors like :
Error:(71, 0) Gradle DSL method not found: 'buildConfigField()' Possible causes:
The project 'app' may be using a version of Gradle that does not contain the method. Gradle settings
The build file may be missing a Gradle plugin. Apply Gradle plugin
I am using gradle 2.7 to build my android app and found these ways to set BuildConfigFields
in different answers like this one but they seem to be outdated for newer versions. What functions can I use to get values from gradle in my application ?
Thank you !