0

I am trying to build an Android application by executing Gradle from a PHP script using exec(), but there is no response, so I am unable to see why the build fails.

When executing the applications gradle wrapper from the terminal (SSH), the whole process works fine, using the following commands:

x:/path/to/project/$ ./gradlew assembleRelease
x:/path/to/project/$ ./gradlew assembleRelease --debug --stacktrace
x:/path/to/project/$ ./gradlew assembleRelease --debug --stacktrace > output.txt

The output works fine and I am able to troubleshoot any possible problems. When executing gradle from a PHP-script, there is no output.

// array for the output to be dumped into
$output_array = array();

// $result is empty (tried with stacetrace, debug and an output file)
$result = exec("cd /path/to/project && ./gradlew assembleRelease", $output_array);

// nothing displayed
var_dump($output_array);

There is no way of me telling where the problem is. I have checked that the required environment variables ($GRADLE_HOME and $ANDROID_HOME) are set using getenv() and they point to the correct path.

Any help would be great!

1 Answer 1

0

I'm no linux specialist, but it seems you launch it (ssh) from "~/path/to/project" (~ meaning your home path).

In php, you're trying to launch it from "/path/to/project" (absolute path from root folder).

try to replace your second command by "ls" so you'll see where you are... and compare with where you should be!

Sign up to request clarification or add additional context in comments.

7 Comments

I have updated my question. The path is correct in my script.
and have you tried a $result = exec("ls && cd ~/path/to/project && ls", $output_array); ? Should help to see if you are where you think you are...
it might be a permission problem too. Are you sure that apache/php have rights to access the folder "path/to/project", and to execute the binary "gradlew"?
can't edit pre-previous comment any more, wanted to add: "~" is the home path of the active user. Your webserver is probably not running under the same user as yourself, so the "~" might mean some different folder for both users. Try the ABSOLUTE path of the folder containing the gradlew binary.
For the path, I use a constant which I have verified is the correct path. I actually do use the absolute path, so I do not replace the home path with "~". I probably should have edited my question to leave out the "~" character, instead (I apologize). The source dumped on the server via a PHP-script, so PHP should have permission to the directory. I took a look in any case, the owner is "www-data".
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.