我已经做过很多Android开发,而无需很好地了解gradle。
理想情况下,在设置virtualenv之后,我将运行python脚本,但是对于这个问题,我对MWE感到满意。
task rem(type: Exec) {
doLast {
exec {
workingDir '.'
commandLine 'dir'
}
}
}
结果是:
> Task :app:rem FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:rem'.
> execCommand == null!
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 2s
1 actionable task: 1 executed
假设我回到炮击之前如何声明任务:
task rem {
没有
(type: Exec)
我得到:> A problem occurred starting process 'command 'dir''
我之前有过
> execCommand == null!
我只有以下
commandLine
可以工作:task rem(type: Exec) {
commandLine 'python', '--version'
}
用
commandLine 'dir'
替换正文失败...
> A problem occurred starting process 'command 'dir''
...
最佳答案
最终偶然发现运行Windows脚本的https://stackoverflow.com/a/37871837/866333并发现链接https://stackoverflow.com/a/50394682/866333更容易。
task rem(type: Exec) {
commandLine 'cmd', '/c', "cd && virtualenv --python=\"C:\Program Files\Python38\python.exe\" C:\Users\XXX\AndroidStudioProjects\YYY\virtualenvs\ZZZ"
}
上面的代码片段取得了很好的成功(使用双引号,因此我可以从早期的计算中替换XXX YYY ZZZ。这虽然不漂亮,但是python脚本会很不错。
希望这将为我节省更多时间。
注意cd以开始(标称)链。我不在预期的目录中。
关于windows - Gradle无法运行我想要的shell命令行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61858323/