First off, if this belongs on Ask Ubuntu, my apologies...I\'m not really sure what forum this falls under.
I\'m attempting to fork and build an Android project from
I am using gradle 3.0 and it needs the directory mentioned in -g parameter to have execute permission. It wasn't executable when we got this error and making it executable solved the problem.
If forking and building script working fine when is executed under your user account in the terminal then a problem is most likely with environment variables and files permissions.
1 It could be that path defined in GRADLE_USER_HOME is not writable by www-data user. To change home dir you could execute gradle -g /path/writable/by-www-user
just before running build script or use in PHP putenv()
to amend 'GRADLE_USER_HOME'.
If you change GRADLE_USER_HOME then also move files like gradle.properties which may be important for you build.
2 Check if gradle command can be executed by www-data
sudo -u www-data `gradle --version`
How to check environment variables for www-user and for your user:
you can use in terminal printenv
to print environment variables. For example for www-data user that would be sudo -u www-data printenv
and for your user just printenv
you can save them to files and compare
sudo -u www-data printenv > wwwdata-env
printenv > my-env
diff --side-by-side --suppress-common-lines wwwdata-env my-env
Then use PHP method putenv()
- to set any missing variables related to Gradle and the project you build.
I encounter this issue because ~/.gradle
is a broken symbolic link. hope it helps.
I have solved it by overriding GRADLE_USER_HOME
enviromental variable.
In ~/.bashrc file, add the next line:
export GRADLE_USER_HOME=/home/www-data/.gradle
Where www-data
is the username.
And restart your session or execute source ~/.bashrc
to apply changes.
For me, @Pawel Dubiel answer didn't work, So I found that adding "-g gradle-user-home" to the Gradle command solved the issue.
gradle build -g gradle-user-home