【问题标题】:"error=2, No such file or directory" when Hosting an executable within Android application在 Android 应用程序中托管可执行文件时出现“错误 = 2,没有这样的文件或目录”
【发布时间】:2018-04-04 20:46:37
【问题描述】:

问题描述

我正在使用一个 android 应用程序,该应用程序托管位于内部存储 (/data/data/APPNAME/files/EXECUTABLE) 中的 arm 可执行文件。

当我像这样检查文件时:

filePath = context.getFilesDir().getPath()+"/SMILExtract-static"
Process process = Runtime.getRuntime().exec("file " + filePath);

shell 输出是:

/data/user/0/app.me.phonestudy/files/SMILExtract-static: ELF shared object, 32-bit LSB arm, dynamic (/usr/lib/libc.so.1), for Android 21, built by NDK r15c (4203891), stripped

所以该文件必须明显存在。
然而,当我使文件可执行并执行它时:

Runtime.getRuntime().exec("/system/bin/chmod 777 " + filePath);
Runtime.getRuntime().exec(filePath);

我收到此错误:

04-04 22:26:41.774 24708-24896/app.me.phonestudy E/AndroidRuntime: FATAL EXCEPTION: data Processing Thread
                                                               Process: app.me.phonestudy, PID: 24708
                                                               java.lang.RuntimeException: java.io.IOException: Cannot run program "/data/user/0/app.me.phonestudy/files/SMILExtract-static": error=2, No such file or directory

                                                                Caused by: java.io.IOException: Cannot run program "/data/user/0/app.me.phonestudy/files/SMILExtract-static": error=2, No such file or directory
                                                                   at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
                                                                   at java.lang.Runtime.exec(Runtime.java:692)
                                                                   at java.lang.Runtime.exec(Runtime.java:525)
                                                                   at java.lang.Runtime.exec(Runtime.java:422)

                                                                Caused by: java.io.IOException: error=2, No such file or directory
                                                                   at java.lang.UNIXProcess.forkAndExec(Native Method)
                                                                   at java.lang.UNIXProcess.<init>(UNIXProcess.java:133)
                                                                   at java.lang.ProcessImpl.start(ProcessImpl.java:128)
                                                                   at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
                                                                   at java.lang.Runtime.exec(Runtime.java:692) 
                                                                   at java.lang.Runtime.exec(Runtime.java:525) 
                                                                   at java.lang.Runtime.exec(Runtime.java:422) 
                                                                   at 

问题

为什么文件明显存在于给定路径却找不到?

我唯一的线索是这篇文章:https://askubuntu.com/questions/133389/no-such-file-or-directory-but-the-file-exists,它提到了在没有安装 32 位支持的 64 位系统上尝试运行 32 位二进制文​​件时的兼容性问题。
因为这篇文章不是专门针对安卓系统的,所以它并没有真正帮助我解决我的问题。

感谢您的建议。

【问题讨论】:

    标签: android arm executable


    【解决方案1】:

    我相信要么它找不到材料,要么你没有正确安装它。

    【讨论】:

    • 既然你的问题是什么可能导致这个问题,我相信这就是导致它的原因。
    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-05
    • 1970-01-01
    • 2017-02-11
    • 2020-04-09
    相关资源
    最近更新 更多