更新后Android gradle 3.0.0 buildConfigField警告

时间:2017-06-19 11:26:38

标签: android android-gradle build.gradle

我最近安装了最新的Canary版Android Studio,目前正在使用Android Gradle插件3.0.0-alpha4(之前为2.3.3)。

我现在收到所有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
}

警告内容如下:

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"

对于我的各种领域和构建类型,其中有100个。我如何解决它们以及实际告诉我的警告是什么?

2 个答案:

答案 0 :(得分:5)

Build system warns you that some buildConfigField is being re-assigned.

The two shown fields are being re-assigned to the same value, which hints that one of the following scenarios might be happening:

  1. your build script is misconfigured and evaluates some expression twice
  2. your build script have duplicate assignments
  3. gradle by itself evaluates the build script twice, and warns you about its own actions

答案 1 :(得分:0)

最幼稚的解决方案是将buildConfigField部分中的所有debug移到defaultConfig部分。