Android:connectedAndroidTest找不到符号.. - > BuildConfigField gradle

时间:2015-02-18 08:26:45

标签: android 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无法识别的。所以我的问题是如何解决这个问题?

谢谢,

1 个答案:

答案 0 :(得分:2)

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", "\"..\""
}