androidgradleparameter-passingbuildconfigandroid-buildconfig

Put property from parameters into a android build config with a default value using gradle?


I would like to grab a parameter from gradle command line -Pfruit=Apple

And then put this parameter into a BuildConfig for every buildType.

I'm trying to achieve using:

buildConfigField("String", "env", "\"${project.fruit}\"")

Unfortunately I don't know how to set default value like "Pear" there, and how to set it for all build types.


Solution

  • Try this :

    buildConfigField("String", "env", project.hasProperty('fruit') ? '"' + project.fruit + '"' : '"Pear"')