I would like to define the assembly configuration where I can use the variable defined in gradle script it self:
def someVar = 512 android { ... buildConfigField 'int', 'SOME_INT_FIELD', someVar }
But this causes the following error:
Error: (25, 0) gradle DSL method not found: 'buildConfigField ()'
Possible reasons:
The PROJECT project may use a version of gradle that does not contain a method. The gradle plugin may not be in the build file.
I could use quotes like:
def someVar = 0 android { ... buildConfigField 'int', 'SOME_INT_FIELD', '"' + someVar + '"' }
But this is due to a compiler error in BuildConfig
// Fields from default config. public static final int SOME_INT_FILED = "512";
So now I am staying with:
def someVar = 0 android { ... buildConfigField 'String', 'SOME_INT_FIELD', '"' + someVar + '"' }
and use it like:
final int value = Integer.valueOf(BuildConfig.SOME_INT_FIELD);
Does anyone have a better solution or am I using buildConfigField incorrectly?
(I also tried using parentheses in conjunction with any possible possibility above.)
source share