Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android gradle 3.0.0 buildConfigField warning after updating

Tags:

I recently installed the latest Canary build of Android Studio which is currently using the Android Gradle plugin 3.0.0-alpha4 (previous was 2.3.3).

I now get a warning for all of my buildConfigFields:

buildTypes {         def BOOLEAN = "boolean"         def STRING = "String"         def INT = "int"         def TRUE = "true"         def FALSE = "false"         def SOME_PER_BUILD_TYPE_FIELD = "SOME_PER_BUILD_TYPE_FIELD"   debug {             buildConfigField BOOLEAN, SOME_PER_BUILD_TYPE_FIELD, FALSE }   release {             buildConfigField BOOLEAN, SOME_PER_BUILD_TYPE_FIELD, TRUE } 

The warnings read like:

Warning:BuildType(debug): buildConfigField 'SOME_PER_BUILD_TYPE_FIELD' value is being replaced: false -> false Warning:BuildType(debug): buildConfigField 'SOME_STRING_FIELD' value is being replaced: "999" -> "999" 

And there is like 100 of them for my various fields and build types. How do I fix them and what is the warning actually telling me?

like image 766
Daniel Wilson Avatar asked Jun 19 '17 11:06

Daniel Wilson


1 Answers

The reason is correctly mentioned by Vasiliy. Just to add a little to it, one possible reason for it could be when you have a buildType that is initialised with any other buildType. e.g. consider the following build configurations:

debug {     buildConfigField 'boolean', 'ENABLE_CRASH_REPORTING', 'false' } stage {     initWith(buildTypes.debug)     buildConfigField 'boolean', 'ENABLE_CRASH_REPORTING', 'true' } release {     buildConfigField 'boolean', 'ENABLE_CRASH_REPORTING', 'true' } 

In this case, you will get warning for buildType stage

Warning:BuildType(stage): buildConfigField 'ENABLE_CRASH_REPORTING' value is being replaced: false -> true

The reason is pretty simple and obvious that stage inherits all fields from debug and then stage replaces it because you might want to assign them different value for stage (like in the case above). A possible workaround could be replacing

initWith(buildTypes.debug) 

with

signingConfig signingConfigs.debug 

This will eliminate the signing error you normally get when building stage builds. But the main difference here in the configuration now is; stage will not inherit build variables from debug in this case and therefore you will not get any warning for this too. Also you will have to redefine all build variables in stage in this case as (already mentioned) stage is no more inherited from debug

like image 199
Rehan Avatar answered Sep 18 '22 19:09

Rehan