Could not find commandLine () method

I am trying to add a pre-pre-build script shell to my gradle / Android-Studio construct. I added the following to app/build.gradle :

 task prePreBuild << { commandLine 'ls' } preBuild.dependsOn prePreBuild 

When I call my assembly using ./gradlew assembleDebug , I get the following error:

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

If I replaced the commandLine line commandLine something like println 'Hello' , then it works fine, and I can see the result from my new task.

I searched for other references to "Could not find commandLine method" and found nothing. What is the correct way to invoke a shell script from this gradle task?

+7
android android-studio gradle
source share
1 answer

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

 task execute(type: Exec) { } 

or

 exec { } 

Further information can be found at https://docs.gradle.org/current/dsl/org.gradle.api.tasks.Exec.html

+13
source share

All Articles