无法为Linux amd64加载本机库’libnative-platform.so’

首先,如果这属于Ask Ubuntu,我很抱歉……我不确定这个论坛是什么。

我正在尝试使用PHPshell脚本从Github派生并构建一个Android项目。 基本上,我是从我写入网站的shell脚本中打印出一些输出。 当您访问该页面并按下某些按钮时,该项目将使用Gradle进行分叉和构建。 PHP代码运行shell脚本,然后在命令运行时将输出打印到浏览器中。

但是,我收到此错误作为我的脚本的输出:

FAILURE: Build failed with an exception. * What went wrong: Failed to load native library 'libnative-platform.so' for Linux amd64. 

该脚本现在只是运行gradle build ,但我打算稍后更改…现在,我正在构建根项目并输出结果。

如果我使用--stacktrace标志运行命令,这是输出:

 * 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 

这是带有--debug标志的输出:

 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] 

我做了一些关于此事的研究并发现了这个论坛post ,但它没有给我任何关于如何解决问题的线索。

进一步的研究使我得到了Github问题 ,这似乎是针对NixOS的,但我正在运行Ubuntu 12.04 CLI。 另外,我应该提到我也在运行Gradle 2.10。

我也试过运行gradle -Dorg.gradle.native=false build ,但结果是一样的。

现在,就用户调用脚本而言,我相信它是www-data,因为我正在运行Apache2 Web服务器和PHP。

这是运行脚本的PHP代码的一小部分,我在另一篇SOpost中find了它:

 &1"; while (@ ob_end_flush()); // end all output buffers if any $proc = popen($command, 'r'); echo '
'; while (!feof($proc)){ echo fread($proc, 1024); @ flush(); } echo '

'; ?>

我现在不知所措,所以我希望有人能引导我find一个新的,可靠的答案。

如果在终端中的用户帐户下执行分叉和构建脚本工作正常,则问题很可能是环境variables和文件权限。

1 可能是GRADLE_USER_HOME中定义的路径不能由www-data用户写入 。 要更改主目录,您可以在运行构建脚本之前执行gradle -g /path/writable/by-www-user ,或者在PHP putenv putenv()以修改’GRADLE_USER_HOME’。

如果您更改GRADLE_USER_HOME,那么还要移动像gradle.properties这样的文件,这对您来说可能很重要。

2检查www-data是否可以执行gradle命令

 sudo -u www-data `gradle --version` 

如何检查www-user和您的用户的环境variables:

您可以在终端printenv使用打印环境variables。 例如对于www-data用户来说,这将是sudo -u www-data printenv ,对于你的用户来说就是printenv

您可以将它们保存到文件并进行比较

 sudo -u www-data printenv > wwwdata-env printenv > my-env diff --side-by-side --suppress-common-lines wwwdata-env my-env 

然后使用PHP方法putenv() – 设置与Gradle和您构建的项目相关的任何缺失variables。

我使用的是gradle 3.0,它需要-g参数中提到的目录才能拥有执行权限。 当我们收到此错误并使其可执行解决问题时,它不可执行。