Modify Gradle buildConfigField at compilation time

24 views Asked by At

I'm facing an issue when I try to populate buildConfigField during compilation time.
For some reason, I have multiple product flavors which haven't the same arguments.
I will simplify as this:
File flavorA.config:

propertyA=property1
propertyB=property2
propertyC=property3
...

File flavorB.config:

propertyA=property1bis
propertyD=property4
propertyE=property5
...

As you can see, A and B shares propertyA but others aren't.
If I put the instruction buildConfigField (string) (string) (string) inside configureEach { flavor -> ... }, it works well, but it's triggered as soon as I synchronize gradle.

If I put the instruction otherwise:

task.register('customTask') { doLast { (here) } }
preBuild.dependsOn customTask

The instruction is triggered during compilation time, but buildConfigField is unknown here...

Is there a way to populate it during compilation?
The main purpose is to share only desired variables to developers (for example production), and to be sure CI doesn't know unexpected variables.
Plus, to display a message if there is a variable missing for desired flavor, I don't want to trigger a message for development environment if I'm running production one...

Thanks!

0

There are 0 answers