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)