Could not find method commandLine()

梦想与她 提交于 2020-05-14 14:46:28

问题


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

When I invoke my build with ./gradlew assembleDebug I get the following error:

Could not find method commandLine() for arguments [ls] on project ':app'

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.

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?


回答1:


You need to indicate the type of the task or use the exec block:

task execute(type: Exec) {

}

or

exec {

}

You can find more info on https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html



来源:https://stackoverflow.com/questions/36185474/could-not-find-method-commandline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!