【发布时间】:2019-12-25 02:03:13
【问题描述】:
android 构建成功,但在运行时抛出错误。
so 和python 文件路径是app\src\main\python。
1.so文件路径更改为app\src\main\jniLibs\arm64-v8a或app\src\main\assets也有同样的错误。
2.在python文件中更改so文件路径,使用/sdcard/FaceDetect/python/andoir.cpython-35m-x86_64-linux-gnu.so也会出现同样的错误。
我使用 chaquopy。如何在python文件中使用so文件? so 文件应该设置在哪里?
谢谢! python文件detect.py:
from ctypes import cdll
import os
def detectImg(img_path):
print("yxq-python::::" + img_path)
print(os.path.abspath(__file__))
print(os.path.dirname(os.path.abspath(__file__)))
# cur = cdll.LoadLibrary('/sdcard/FaceDetect/python/andoir.cpython-35m-x86_64-linux-gnu.so')
cur = cdll.LoadLibrary('./andoir.cpython-35m-x86_64-linux-gnu.so')
model_path = "/sdcard/FaceDetect/python/sfd_face.pth"
cur.diaoyong(img_path, model_path)
错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.boyun.hisensetestheadcount, PID: 1642
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.boyun.hisensetestheadcount/com.boyun.hisensetestheadcount.MainActivity}: com.chaquo.python.PyException: OSError: dlopen failed: library "./andoir.cpython-35m-x86_64-linux-gnu.so" not found
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2671)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2732)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1483)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6141)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:802)
Caused by: com.chaquo.python.PyException: OSError: dlopen failed: library "./andoir.cpython-35m-x86_64-linux-gnu.so" not found
at <python>.ctypes.__init__(__init__.py:348)
at <python>.ctypes.LoadLibrary(__init__.py:426)
at <python>.detect.detectImg(detect.py:9)
at <python>.chaquopy_java.call(chaquopy_java.pyx:283)
at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:255)
at com.chaquo.python.PyObject.callAttrThrows(Native Method)
at com.chaquo.python.PyObject.callAttr(PyObject.java:207)
at com.boyun.hisensetestheadcount.MainActivity.detectImg(MainActivity.java:245)
at com.boyun.hisensetestheadcount.MainActivity.onCreate(MainActivity.java:86)
at android.app.Activity.performCreate(Activity.java:6709)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
【问题讨论】:
-
这个文件
andoir.cpython-35m-x86_64-linux-gnu.so是什么,你从哪里得到的?您将无法获取为 Linux x86_64 构建的 .so 文件并在 Android 上加载它们:操作系统库和处理器架构不同。 -
so文件是python制作的算法包。
-
so文件是python制作的算法包。算法工程师将python文件打包成so文件,我在android中使用so文件的方法。 Android不是linux系统吗? android不能使用编译好的so文件用于linux x64系统?
-
很遗憾,由于我上面提到的原因,它不能。但是,如果您想为 Android 构建自己的原生 Python 模块,我们(Chaquopy 的开发人员)也许可以为您提供一些工具。如果您有兴趣,请contact us 提供您的具体情况。