kivy / python-for-android

Turn your Python application into an Android APK
https://python-for-android.readthedocs.io
MIT License
8.33k stars 1.84k forks source link

can't use opencv, "dlopen failed: cannot locate symbol" #2026

Open yimelia opened 4 years ago

yimelia commented 4 years ago

Versions

My environment is KivyCompleteVM, and I update the kivy repo to develop latest

Description

in my python file:

import cv2

but got this error:

I/python  ( 7920):     import cv2
I/python  ( 7920): ImportError: dlopen failed: cannot locate symbol "PyBool_Type
" referenced by "cv2.so"...

buildozer.spec

Command:

p4a apk --private ./code --package=org.test.myapp --name "My application" --version 0.1  --arch=armeabi-v7a --bootstrap=sdl2 --requirements=opencv,numpy,websocket-client,python3,kivy,rpyc --ndk_dir /home/kivy/Android/android-ndk-r17c/ --sdk_dir /home/kivy/Android/android-sdk-28/  --android_api 27

Logs

I/python  ( 7920):     import cv2
I/python  ( 7920): ImportError: dlopen failed: cannot locate symbol "PyBool_Type
" referenced by "cv2.so"...
yimelia commented 4 years ago

I re-run the command, but the resulting apk size has changed. and I can't import cv2:

I/python  (10187):     from .aircv import *
I/python  (10187):   File "/sdcard/kv/airtest/aircv/aircv.py", line 5, in <modul
e>
I/python  (10187):     import cv2
I/python  (10187): ModuleNotFoundError: No module named 'cv2'

some strange things:

  1. I found a cv2.so in the first.apk, but not in the second.apk. I use the same command, only different is the --dist_name
  2. This error(ImportError: dlopen failed:) occurred when I used one armeabi-v7a mobile phone, when I use a arm64-v8a phone it seems working. but in the command, I use --arch=armeabi-v7a
  3. now I meet other problems, I add Pillow in the requirements, but when I finish build, I got the No module named cv2 error, and I can't find the cv2.so in APK. and when building, this error will occur, but it seems not very important? image

I'm not very familiar with this project, if I make any mistake, please tell me.