我遇到以下问题。
我有一个主文件 app.gradle,我称之为
defaultConfig {
resValue "string", "hello world", "1234567890"
}
这工作正常。 现在我尝试将该功能移动到使用
在 header 上导入的另一个文件apply from: "gradle_tasks.gradle"
包含以下内容:
ext.AddResourcesVariables = { ->
resValue "string", "hello world", "1234567890"
}
并从主 gradle 中调用它
defaultConfig {
AddResourcesVariables()
}
然后我收到以下错误:
Error:Gradle DSL method not found: 'resValue()'
我是否缺少一些导入内容?
谢谢!
最佳答案
resValue()
是来自 defaultConfig
的 dsl 方法。您无法导入它。
您可以在不同的文件中定义[类型][名称][值]的映射
ext.valueMap = [
[type: "string", name: "hello world", value: "1234567890"],
[type: "string", name: "hello world", value: "1234567890"],
]
然后在脚本中对其进行迭代
defaultConfig{
valueMap.each {
resValue it.type, it.name, it.value
}
}
尚未编译,但应该接近。
关于android - 从另一个文件调用 gradle resValue 会导致 "Error:Gradle DSL method not found: ' resValue( )'",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44952983/