0

I've done a lot of Android dev never needing to understand gradle well.

Ideally I'd be running a python script after setting up a virtualenv, but for this question I'm happy with a MWE.

task rem(type: Exec)  {
    doLast {
        exec {
            workingDir '.'
            commandLine 'dir'
        }
    }
}

Results in:

> 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

Let's say I go back to how I was declaring my tasks before shelling out:

task rem  {

without (type: Exec) I get:

> A problem occurred starting process 'command 'dir''

where before I had

> execCommand == null!

I have only got the following commandLine to work:

task rem(type: Exec)  {
    commandLine 'python', '--version'
}

replacing body with commandLine 'dir' fails with

...
> A problem occurred starting process 'command 'dir''
...
John
  • 6,433
  • 7
  • 47
  • 82

1 Answers1

0

Eventually stumbled on https://stackoverflow.com/a/37871837/866333 for running windows scripts and found chaining, https://stackoverflow.com/a/50394682/866333, more easily.

task rem(type: Exec)  {
    commandLine 'cmd', '/c', "cd && virtualenv --python=\"C:\Program Files\Python38\python.exe\" C:\Users\XXX\AndroidStudioProjects\YYY\virtualenvs\ZZZ"
}

Had good success with the above snippet (using double quotes so I could substitute XXX YYY ZZZ from earlier computations. It isn't pretty but the python script will be.

Hopefully this will save another gradle newbie the hours I needed.

Note the cd to begin the (nominal) chain. I was not in the directory I expected.

John
  • 6,433
  • 7
  • 47
  • 82