我在build.gradle中创建了一个额外的任务,为公共github repo提供密钥。
afterEvaluate {
initFabricPropertiesIfNeeded()
}
def initFabricPropertiesIfNeeded() {
def propertiesFile = file('fabric.properties')
if (!propertiesFile.exists()) {
def commentMessage = "This is autogenerated fabric property from system environment to prevent key to be committed to source control."
ant.propertyfile(file: "fabric.properties", comment: commentMessage) {
entry(key: "apiSecret", value: FABRIC_API_SECRET)
entry(key: "apiKey", value: FABRIC_API_KEY)
}
}}
我想用travis ci服务器端构建它,并在环境变量设置中添加这两个变量FABRIC_API_SECRET和FABRIC_API_KEY。
但构建因此异常而失败。
配置项目':app'时出现问题。
在项目':app'上找不到属性'FABRIC_API_SECRET'。
任何想法如何解决这个问题?
答案 0 :(得分:2)
如果您在Travis CI设置面板中设置了这些环境变量值,则应该能够使用gradle访问环境值:
entry(key: "apiSecret", value: "$System.env.FABRIC_API_SECRET")
entry(key: "apiKey", value: "$System.env.FABRIC_API_KEY")
错误的原因是gradle认为您正在调用属性值而不是访问字符串。