Android :connectedAndroid测试找不到符号.. -> BuildConfigField gradle

Android :connectedAndroidTest can't find symbol .. -> BuildConfigField gradle

我已经使用 gradle(Android 项目设置了一些自定义构建任务,现在这些任务工作正常。此任务的示例:

TEST {
    buildConfigField "String", "KEY", "\"..\""
    buildConfigField "String", "CLIENT_ID", "\"\""
    buildConfigField "String", "PROTOCOL_VERSION", "\"5.0.0\""
    buildConfigField "String", "BACKEND_ENVIRONMENT", "\"..\""
    buildConfigField "String", "BACKEND_COUNTRY", "\"..\""

    debuggable true
    jniDebuggable true
    signingConfig signingConfigs.debug
}

现在的问题是,当我 运行 预定义任务 connectedAndroidTest 时,它会抱怨代码中缺少变量,即无法识别的 BuildConfigFields。所以我的问题是如何解决这个问题?

谢谢,

debug buildType 定义变量(仅用于调试版本):

buildTypes {
    debug {
        buildConfigField "String", "KEY", "\"..\""
        buildConfigField "String", "CLIENT_ID", "\"\""
        buildConfigField "String", "PROTOCOL_VERSION", "\"5.0.0\""
        buildConfigField "String", "BACKEND_ENVIRONMENT", "\"..\""
        buildConfigField "String", "BACKEND_COUNTRY", "\"..\""
    }
}

或在 defaultConfig 中(对于所有版本):

defaultConfig {
    buildConfigField "String", "KEY", "\"..\""
    buildConfigField "String", "CLIENT_ID", "\"\""
    buildConfigField "String", "PROTOCOL_VERSION", "\"5.0.0\""
    buildConfigField "String", "BACKEND_ENVIRONMENT", "\"..\""
    buildConfigField "String", "BACKEND_COUNTRY", "\"..\""
}