ImportError: dlopen failed: cannot locate symbol "_PyGen_Send"

532 views
Skip to first unread message

Kivy user

unread,
Jun 7, 2023, 9:21:42 PM6/7/23
to Kivy users support
When I open the apk built with Buildozer1.5.0, it is immediately closed and the following error is displayed in Android Studio's Logcat:

   Traceback (most recent call last):
      File "/content/XXX/.buildozer/android/app/main.py", line 8, in <module>
      File "/content/XXX/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/xxx/arm64-v8a/kivy/core/window/__init__.py", line 21, in <module>
      File "/content/XXX/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/xxx/arm64-v8a/kivy/base.py", line 29, in <module>
      File "/content/XXX/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/python-installs/xxx/arm64-v8a/kivy/event.py", line 8, in <module>
   ImportError: dlopen failed: cannot locate symbol "_PyGen_Send" referenced by "/data/data/org.test.xxx/files/app/_python_bundle/site-packages/kivy/_event.so"...
   Python for android ended.

The 8th line of main.py is below:

   from kivy.core.window import Window

A month ago, an apk built with the same execution environment and the same buildozer.spec was able to launch successfully.

I tried the following buildozer.spec requirements, but they all gave the same "dlopen failed" error:

   requirements = kivy,kivymd,cython,...
   requirements = kivy==2.1.0,kivymd==1.1.1,cython==0.29.32,...
   requirements = kivy==2.1.0,kivymd==1.1.1,cython==0.29.34,...
   requirements = kivy==2.2.0,kivymd==1.1.1,cython==0.29.32,...
   requirements = kivy==2.2.0,kivymd==1.1.1,cython==0.29.34,...

I have been struggling with this error for a week.
I would appreciate it if someone could help me.

Robert

unread,
Jun 7, 2023, 9:55:09 PM6/7/23
to Kivy users support

It's related to Python 3.10 which p4a recently started using, so that is why it appeared.
Use:
The current kivy (2.2.0) and
Cython 0.29.33 (see https://github.com/kivy/buildozer/blob/master/docs/source/installation.rst#android-on-ubuntu-2004-and-2204-64bit)

Also Cython is not a buildozer.spec requirement, it is an install dependency. Which is perhaps why your tests fail.

KivyMD is a moving target, and I have no comment on it.
Message has been deleted

Kivy user

unread,
Jun 8, 2023, 2:36:57 PM6/8/23
to Kivy users support
Thank you very much, Robert!
After building the apk on Google Colab(Ubuntu 20.04.5 LTS, Python 3.10.11) with the following steps, it opened successfully!
(I removed "cython==0.29.xx" from the buildozer.spec requirements)

   !sudo apt update
   !sudo apt install -y git zip unzip openjdk-17-jdk python3-pip autoconf libtool pkg-config zlib1g-dev libncurses5-dev libncursesw5-dev libtinfo5 cmake libffi-dev libssl-dev
   !pip3 install --upgrade Cython==0.29.33 virtualenv
   !export PATH=$PATH:~/.local/bin/

   !python -m pip install --upgrade pip
   !pip install buildozer==1.5.0

   !buildozer init
   !buildozer -v android debug


However, when I added "pycryptodome==3.7.3" to the requirements in buildozer.spec, I got the following error when building with Buildozer:

   [INFO]:    Building cffi for armeabi-v7a
   [INFO]:    cffi apparently isn't already in site-packages
   [INFO]:    Building compiled components in cffi
   [INFO]:    -> directory context /content/xxx/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/cffi/armeabi-v7a__ndk_target_28/cffi
                   :
   [DEBUG]:   2 warnings and 2 errors generated.
   [DEBUG]:   error: command '/root/.buildozer/android/platform/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang' failed with exit code 1
   Exception in thread background thread for pid 51966:

   Traceback (most recent call last):
     File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
       self.run()
     File "/usr/lib/python3.10/threading.py", line 953, in run
       self._target(*self._args, **self._kwargs)
     File "/root/.local/lib/python3.10/site-packages/sh.py", line 1641, in wrap
       fn(*rgs, **kwargs)
     File "/root/.local/lib/python3.10/site-packages/sh.py", line 2569, in background_thread
       handle_exit_code(exit_code)
     File "/root/.local/lib/python3.10/site-packages/sh.py", line 2269, in fn
       return self.command.handle_command_exit_code(exit_code)
     File "/root/.local/lib/python3.10/site-packages/sh.py", line 869, in handle_command_exit_code
       raise exc
   sh.ErrorReturnCode_1:
   
     RAN: /content/xxx/.buildozer/android/platform/build-arm64-v8a_armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build_ext -v

I tried adding "cffi==1.13.2" to requirements but got the same error.


2023年6月8日木曜日 10:55:09 UTC+9 Robert:

Robert

unread,
Jun 8, 2023, 5:25:09 PM6/8/23
to Kivy users support
Looks like the actual error message is missing from your post.

Kivy user

unread,
Jun 8, 2023, 9:20:52 PM6/8/23
to Kivy users support
Thank you for your prompt reply!

After adding "p4a.branch = develop" to buildozer.spec, the build was successful.
However, when I open the apk, "from Crypto.Cipher import AES" says "AttributeError: undefined symbol: PyObject_GetBuffer".

I would like to test by specifying the Python version of the apk to 3.8.15, is the following writing correct?

   requirements = python3==3.8.15,hostpython3==3.8.15,kivy==2.2.0,kivymd==1.1.1,...

Also, is it necessary to change the Python version of the execution environment?
(Current execution environment Python version: 3.10.12)

2023年6月9日金曜日 6:25:09 UTC+9 Robert:

Kivy user

unread,
Jun 8, 2023, 10:32:07 PM6/8/23
to Kivy users support
I used the writing below and now everything works fine!

   requirements = python3==3.8.15,hostpython3==3.8.15,kivy==2.2.0,kivymd==1.1.1,kivy-garden==0.1.5,pillow==9.3.0,pycrypto==2.6.1,...
   * "p4a.branch = develop" is not specified.
   * The Python version of the execution environment has not been changed.

2023年6月9日金曜日 10:20:52 UTC+9 Kivy user:

Robert

unread,
Jun 9, 2023, 12:13:14 AM6/9/23
to Kivy users support
Well whatever works I suppose.

Generally for p4a version pinning of any requirement is probably not a good idea, though with unclear limitations you can do it. Many of us control freaks may have a hard time with that.

PyObject_GetBuffer() exists in Python 3.10 so I have no suggestion as to the cause

Reply all
Reply to author
Forward
0 new messages