找不到方法commandLine() [英] Could not find method commandLine()
问题描述
我正在尝试将预构建前的shell脚本添加到我的gradle/Android-Studio构建中.我已将以下内容添加到app/build.gradle
:
I'm attempting to add a pre-pre-build shell script to my gradle/Android-Studio build. I've added the following to app/build.gradle
:
task prePreBuild << {
commandLine 'ls'
}
preBuild.dependsOn prePreBuild
当我使用./gradlew assembleDebug
调用构建时,出现以下错误:
When I invoke my build with ./gradlew assembleDebug
I get the following error:
Could not find method commandLine() for arguments [ls] on project ':app'
如果将commandLine
行替换为println 'Hello'
,则可以正常工作,并且可以看到新任务的输出.
If I replace the commandLine
line with something like println 'Hello'
then it works fine, and I can see the output from my new task.
我搜索了其他提及找不到方法commandLine"的内容,但一无所获.从此gradle任务中调用Shell脚本的正确方法是什么?
I searched for other mentions of "Could not find method commandLine" and found nothing. What is the correct way to invoke a shell script from this gradle task?
推荐答案
您需要指出任务的类型或使用exec
块:
You need to indicate the type of the task or use the exec
block:
task execute(type: Exec) {
}
或
exec {
}
您可以在 https://docs.gradle.org上找到更多信息./current/dsl/org.gradle.api.tasks.Exec.html
这篇关于找不到方法commandLine()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!