找不到方法commandLine() [英] Could not find method commandLine()

查看:94
本文介绍了找不到方法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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆