gpt4 book ai didi

android - 如何在gradle中为任务设置绝对路径

转载 作者:行者123 更新时间:2023-11-30 05:01:43 27 4
gpt4 key购买 nike

我有一个像这样的基本任务

task copy-Library(type: Copy) {
from 'build/outputs/aar/app-debug_-debug.aar'
into "D:\\root\\path\\to\\directory\\Plugins\\Android"
rename { String fileName ->
fileName.replace("app-debug_-debug.aar", "myLibray-debug.aar")
}
}

一切正常

但我想将路径 "D:\\root\\path\\to\\directory\\Plugins\\Android" 放入某个变量中,这样我就可以从其他地方调用任务

进入我的路径

我猜我的 gradle 任务会这样结束

\\ set the path variable
how.do.I.set myPath = "D:\\root\\path\\to\\directory\\Plugins\\Android"

task copy-Library(type: Copy) {
from 'build/outputs/aar/app-debug_-debug.aar'
into myPath
rename { String fileName ->
fileName.replace("app-debug_-debug.aar", "myLibray-debug.aar")
}
}

这样我就可以添加另一个使用相同路径的任务?

task deleteLibrary(type: Delete){
delete fileTree(myPath) {
include '**/*.ext'
}
}

最佳答案

我认为 def 是你想要的:

def myPath  = "D:\\root\\path\\to\\directory\\Plugins\\Android" //define variable myPath 



task copy-Library(type: Copy) {
from 'build/outputs/aar/app-debug_-debug.aar'
into myPath //"$myPath" also should work
rename { String fileName ->
fileName.replace("app-debug_-debug.aar", "myLibray-debug.aar")
}
}

task deleteLibrary(type: Delete){
delete fileTree($myPath) {
include '**/*.ext'
}
}

参见 writing_build_scripts

关于android - 如何在gradle中为任务设置绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58137593/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com