无法为Linux amd64加载本机库'libnative-platform.so' [英] Failed to load native library 'libnative-platform.so' for Linux amd64

查看:242
本文介绍了无法为Linux amd64加载本机库'libnative-platform.so'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,如果这属于Ask Ubuntu,我深表歉意...我不太确定这属于哪个论坛.

First off, if this belongs on Ask Ubuntu, my apologies...I'm not really sure what forum this falls under.

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

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.

但是,我的脚本输出出现此错误:

However, I am getting this error as the output of my script:

FAILURE: Build failed with an exception.

* What went wrong:
Failed to load native library 'libnative-platform.so' for Linux amd64.

该脚本现在暂时仅运行gradle build,但我打算稍后进行更改...现在,我只是在构建根项目并输出结果.

The script is simply running gradle build for now but I intend to change that later...right now, I'm just working on building the root project and outputting the result.

如果使用--stacktrace标志运行命令,则为以下输出:

Here's the output if I run the command with the --stacktrace flag:

* 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]

我对此事进行了一些研究,发现此论坛帖子,但是它没有给我任何有关如何解决此问题的线索.

I did some research on this matter and found this forum post, but it didn't give me any leads as to how to fix the issue.

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

Further research led me to a Github issue, 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.

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

I also tried running gradle -Dorg.gradle.native=false build as well, but the outcome was the same.

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

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.

这是运行脚本的PHP代码的一小段,我在另一篇 SO帖子中找到了

Here's a little snippet of the PHP code that runs the script, which I found on another 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>';
?>

我现在很茫然,所以我希望有人可以带领我找到一个新的,可靠的答案.

I'm at a loss now, so I'm hoping someone can lead me to a new, reliable answer.

推荐答案

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

If forking and building script working fine when is executed under your user account in the terminal then a problem is most likely with environment variables and files permissions.

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

1 It could be that path defined in GRADLE_USER_HOME is not writable by www-data user. To change home dir you could execute gradle -g /path/writable/by-www-user just before running build script or use in PHP putenv() to amend 'GRADLE_USER_HOME'.

如果更改了GRADLE_USER_HOME,则还移动了gradle.properties之类的文件,这可能对您的构建很重要.

If you change GRADLE_USER_HOME then also move files like gradle.properties which may be important for you build.

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

2 Check if gradle command can be executed by www-data

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


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

您可以在终端printenv中使用它来打印环境变量.例如,对于www-data用户而言,该用户为sudo -u www-data printenv,对于您的用户而言,其printenv

you can use in terminal printenv to print environment variables. For example for www-data user that would be sudo -u www-data printenv and for your user just printenv

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

you can save them to files and compare

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

然后使用PHP方法putenv()-设置与Gradle和您构建的项目相关的所有缺失变量.

Then use PHP method putenv() - to set any missing variables related to Gradle and the project you build.

这篇关于无法为Linux amd64加载本机库'libnative-platform.so'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆