gpt4 book ai didi

php - 无法为 Linux amd64 加载 native 库 'libnative-platform.so'

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:27:02 25 4
gpt4 key购买 nike

首先,如果这属于 Ask Ubuntu,我很抱歉...我不太确定它属于哪个论坛。

我正在尝试使用 PHP 和 shell 脚本从 Github fork 并构建一个 Android 项目。基本上,我正在打印我写入网站的 shell 脚本的一些输出。当您访问该页面并按下一些按钮时,该项目将使用 Gradle 进行 fork 和构建。 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]

我对此事做了一些研究,发现 this forum post ,但它没有给我任何解决问题的线索。

进一步的研究使我找到了 Github issue ,它似乎适用于 NixOS,但我正在运行 Ubuntu 12.04 CLI。另外,我应该提到我也在运行 Gradle 2.10。

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

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

这是运行脚本的一小段 PHP 代码,我在另一个 SO post 上找到了它:

<?php
$command = "sh /home/andrew/scripts/build.sh 2>&1";
while (@ ob_end_flush()); // end all output buffers if any
$proc = popen($command, 'r');
echo '<pre style="border-radius: 5px; padding:4px; color:black; background:#ffffff" align="left">';
while (!feof($proc)){
echo fread($proc, 1024);
@ flush();
}
echo '</pre>';
?>

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

最佳答案

如果在终端中以您的用户帐户执行时 fork 和构建脚本工作正常,则很可能是环境变量和文件权限存在问题。

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

如果您更改 GRADLE_USER_HOME,那么还要移动 gradle.properties 等文件,这对您的构建可能很重要。

2 查看gradle命令是否可以通过www-data执行

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

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

您可以在终端中使用 printenv 来打印环境变量。例如,对于 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 和您构建的项目相关的缺失变量。

关于php - 无法为 Linux amd64 加载 native 库 'libnative-platform.so',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38519643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com