title: Failed to load native library 'libnative-platform.so' for Linux amd64
body: <p>First off, if this belongs on Ask Ubuntu, my apologies...I'm not really sure what forum this falls under.</p>
  
  <p>I'm attempting to fork and build an Android project from Github using PHP and a shell script. Basically, I'm printing out some output from a shell script I wrote into a website. When you visit the page, and press some buttons, the project is forked and built using Gradle. The PHP code runs the shell script, and then prints the output into the browser as the command runs.</p>
  
  <p>However, I am getting this error as the output of my script:</p>
  
  <pre><code>FAILURE: Build failed with an exception.
  
  * What went wrong:
  Failed to load native library 'libnative-platform.so' for Linux amd64.
  </code></pre>
  
  <p>The script is simply running <code>gradle build</code> for now but I intend to change that later...right now, I'm just working on building the root project and outputting the result.</p>
  
  <p>Here's the output if I run the command with the <code>--stacktrace</code> flag:</p>
  
  <pre><code>* Exception is:
  net.rubygrapefruit.platform.NativeException: Failed to load native library 'libnative-platform.so' for Linux amd64.
      at net.rubygrapefruit.platform.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:49)
      at net.rubygrapefruit.platform.Native.init(Native.java:55)
      at org.gradle.internal.nativeintegration.services.NativeServices.initialize(NativeServices.java:74)
      at org.gradle.internal.nativeintegration.services.NativeServices.initialize(NativeServices.java:60)
      at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:203)
      at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
      at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
      at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
      at org.gradle.launcher.Main.doAction(Main.java:33)
      at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:622)
      at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
      at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
      at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
  Caused by: java.io.IOException: No such file or directory
      at java.io.UnixFileSystem.createFileExclusively(Native Method)
      at java.io.File.createNewFile(File.java:959)
      at net.rubygrapefruit.platform.internal.NativeLibraryLocator.find(NativeLibraryLocator.java:39)
      at net.rubygrapefruit.platform.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:41)
      ... 16 more
  </code></pre>
  
  <p>And here is the output with the <code>--debug</code> flag:</p>
  
  <pre><code>06:21:43.710 [ERROR] [org.gradle.BuildExceptionReporter] 
  06:21:43.740 [ERROR] [org.gradle.BuildExceptionReporter] FAILURE: Build failed with an exception.
  06:21:43.747 [ERROR] [org.gradle.BuildExceptionReporter] 
  06:21:43.747 [ERROR] [org.gradle.BuildExceptionReporter] * What went wrong:
  06:21:43.748 [ERROR] [org.gradle.BuildExceptionReporter] Failed to load native library 'libnative-platform.so' for Linux amd64.
  06:21:43.749 [ERROR] [org.gradle.BuildExceptionReporter] 
  06:21:43.750 [ERROR] [org.gradle.BuildExceptionReporter] * Exception is:
  06:21:43.752 [ERROR] [org.gradle.BuildExceptionReporter] net.rubygrapefruit.platform.NativeException: Failed to load native library 'libnative-platform.so' for Linux amd64.
  06:21:43.753 [ERROR] [org.gradle.BuildExceptionReporter]    at net.rubygrapefruit.platform.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:49)
  06:21:43.753 [ERROR] [org.gradle.BuildExceptionReporter]    at net.rubygrapefruit.platform.Native.init(Native.java:55)
  06:21:43.754 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.nativeintegration.services.NativeServices.initialize(NativeServices.java:74)
  06:21:43.754 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.internal.nativeintegration.services.NativeServices.initialize(NativeServices.java:60)
  06:21:43.755 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:203)
  06:21:43.756 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
  06:21:43.756 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
  06:21:43.756 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
  06:21:43.757 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.Main.doAction(Main.java:33)
  06:21:43.758 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
  06:21:43.759 [ERROR] [org.gradle.BuildExceptionReporter]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  06:21:43.759 [ERROR] [org.gradle.BuildExceptionReporter]    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  06:21:43.760 [ERROR] [org.gradle.BuildExceptionReporter]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  06:21:43.760 [ERROR] [org.gradle.BuildExceptionReporter]    at java.lang.reflect.Method.invoke(Method.java:622)
  06:21:43.761 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
  06:21:43.761 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
  06:21:43.762 [ERROR] [org.gradle.BuildExceptionReporter]    at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
  06:21:43.762 [ERROR] [org.gradle.BuildExceptionReporter] Caused by: java.io.IOException: No such file or directory
  06:21:43.763 [ERROR] [org.gradle.BuildExceptionReporter]    at java.io.UnixFileSystem.createFileExclusively(Native Method)
  06:21:43.763 [ERROR] [org.gradle.BuildExceptionReporter]    at java.io.File.createNewFile(File.java:959)
  06:21:43.764 [ERROR] [org.gradle.BuildExceptionReporter]    at net.rubygrapefruit.platform.internal.NativeLibraryLocator.find(NativeLibraryLocator.java:39)
  06:21:43.764 [ERROR] [org.gradle.BuildExceptionReporter]    at net.rubygrapefruit.platform.internal.NativeLibraryLoader.load(NativeLibraryLoader.java:41)
  06:21:43.765 [ERROR] [org.gradle.BuildExceptionReporter]    ... 16 more
  06:21:43.765 [ERROR] [org.gradle.BuildExceptionReporter]
  </code></pre>
  
  <p>I did some research on this matter and found <a href="https://community.bitnami.com/t/gradle-doesnt-work-libnative-platform-so/40686" rel="noreferrer">this forum post</a>, but it didn't give me any leads as to how to fix the issue.</p>
  
  <p>Further research led me to a <a href="https://github.com/NixOS/nixpkgs/issues/14596" rel="noreferrer">Github issue</a>, which appears to be for NixOS, but I'm running Ubuntu 12.04 CLI. Also, I should mention I'm running Gradle 2.10 as well.</p>
  
  <p>I also tried running <code>gradle -Dorg.gradle.native=false build</code> as well, but the outcome was the same.</p>
  
  <p>Now, as far as what user is calling the script, I believe it is www-data as I'm running an Apache2 web server and PHP. </p>
  
  <p>Here's a little snippet of the PHP code that runs the script, which I found on another <a href="https://stackoverflow.com/a/20109859/2844992">SO post</a>:</p>
  
  <pre><code>&lt;?php
      $command = "sh /home/andrew/scripts/build.sh 2&gt;&amp;1";
      while (@ ob_end_flush()); // end all output buffers if any
      $proc = popen($command, 'r');
      echo '&lt;pre style="border-radius: 5px; padding:4px; color:black; background:#ffffff" align="left"&gt;';
      while (!feof($proc)){
          echo fread($proc, 1024);
          @ flush();
      }
      echo '&lt;/pre&gt;';
  ?&gt;
  </code></pre>
  
  <p>I'm at a loss now, so I'm hoping someone can lead me to a new, reliable answer.</p>