Android gradle 3.0.0 buildConfigField warning after update

I recently installed the latest version of Canary based on Android Studio, which currently uses the Android Gradle 3.0.0-alpha4 (the previous one was 2.3.3 ).

Now I get a warning for all 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 } 

Warnings read as follows:

 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 for their different fields and assembly types, there are as many as 100 of them. How can I fix them and what really warns me?

+13
source share
3 answers

The build system warns you that some buildConfigField reassigned.

The two displayed fields are reset to the same value, which indicates that one of the following scenarios may occur:

  • your build script is misconfigured and evaluates some expression twice
  • your build script has duplicate assignments
  • gradle itself computes the script construct twice and warns you of its actions
+6
source

The reason is correctly indicated by Basil . Just adding a little to this, one possible reason for this may be when you have a buildType that initializes with any other buildType. For example, consider the following assembly 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 receive a warning for the buildType stage

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

The reason is pretty simple and obvious that stage inherits all fields from debugging, and then stage replaces it, because you can assign them a different value for stage (as in the case above). A possible workaround might be to replace

 initWith(buildTypes.debug) 

with

 signingConfig signingConfigs.debug 

This will fix the signature error that you usually get when assembling the build steps. But the main difference here is in the configuration now; The stage will not inherit debug assembly variables in this case, and therefore you will not receive any warning for this either. Also in this case, you will have to redefine all the assembly variables in the stage, since the (already mentioned) stage is no longer inherited from debugging.

+17
source

The most naive solution is to move all the buildConfigField of the debug section to the defaultConfig section.

0
source

Source: https://habr.com/ru/post/1268981/


All Articles