我已经使用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
无法识别的。所以我的问题是如何解决这个问题?
谢谢,
答案 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", "\"..\""
}