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!

UAJ
  • 11
  • 1

1 Answers1

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!

fpierrat
  • 739
  • 7
  • 25
  • I have updated my question. The path is correct in my script. – UAJ Dec 16 '14 at 13:59
  • 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... – fpierrat Dec 16 '14 at 14:03
  • 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"? – fpierrat Dec 16 '14 at 14:12
  • 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. – fpierrat Dec 16 '14 at 14:15
  • 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". – UAJ Dec 16 '14 at 14:47
  • Does a simple command like `exec("ls",$output_array);` work? Just to be sure your php has exec right... also check your linux errorlogs, or try this to get more details: http://stackoverflow.com/a/539030/3872061 – fpierrat Dec 16 '14 at 14:55
  • Using the link you provided, I was able to use the solution to finally get a response (exception as it turns out) from the server. Thanks! – UAJ Dec 17 '14 at 08:44