1

I'm trying to add BuildConfig variable using gradle. I see that buildConfigField is valid when I call it on gradle buildTypes: release/debug and also on defaultConfig

but I'm trying to create this inside gradle task. for example:

task myTask{
    buildConfigField 'String', 'Test', '"value"'
} 

and then call my task. but in that case when I call myTask, gradle is failed and I'm getting:

"could not find method buildConfigField" 

is there any option to call buildConfigField and make it work inside task?

Elior
  • 3,178
  • 6
  • 37
  • 67
  • 1
    Take a look here, it might help you find a way to solve this problem https://stackoverflow.com/questions/28474958/gradle-task-to-change-a-boolean-in-build-config – TOvidiu Oct 23 '18 at 15:48
  • @Skenia tnx! it's helped! – Elior Oct 23 '18 at 15:53

1 Answers1

5

Thanks to @Skenia suggesting this post

I was able to find a solution, using the answer of Marian Klühspies there.

so for anyone who encounter this in the future, you can use this

android.defaultConfig.buildConfigField "String", "value", "1"

inside tasks and this will work

Elior
  • 3,178
  • 6
  • 37
  • 67