Failed to load native library 'libnative-platform.so' for Linux amd64

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.


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.