2017-07-06 25 views
0

我有以下問題。從另一個文件中調用gradle resValue會導致「錯誤:找不到Gradle DSL方法:'resValue()'」

我有一個主文件app.gradle,我叫

defaultConfig { 
    resValue "string", "hello world", "1234567890" 
} 

該工程確定。 現在我試圖移動該功能對進口的頭另一個文件與

apply from: "gradle_tasks.gradle" 

具有以下內容:

ext.AddResourcesVariables = { -> 
    resValue "string", "hello world", "1234567890" 
} 

並從主用的gradle

defaultConfig { 
    AddResourcesVariables() 
} 
叫它

然後我得到以下錯誤:

​​

我是否缺少一些導入?

謝謝!

回答

2

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 
    } 
} 

有不編譯它,但應該接近。

+0

是的,這就是我現在這樣做,但我徘徊,爲什麼我不能從該腳本調用resValue。也許我可以在該函數上發送defaultConfig類 – Hug

+0

您的答案適用於您的具體情況,但如果我想創建一個生成此映射的函數,那麼該錯誤再次顯示'錯誤:未找到Gradle DSL方法:'resValue( )'' – Hug

+1

我終於通過函數parmeter發送了defaultConfig變量,現在我可以調用defaultConfig.resValue(...) – Hug

相關問題