2

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.

pixel
  • 24,905
  • 36
  • 149
  • 251

1 Answers1

7

Try this :

buildConfigField("String", "env", project.hasProperty('fruit') ? '"' + project.fruit + '"' : '"Pear"')
Martin Zeitler
  • 1
  • 19
  • 155
  • 216
ToYonos
  • 16,469
  • 2
  • 54
  • 70