hbldh / bleak

A cross platform Bluetooth Low Energy Client for Python using asyncio
MIT License
1.83k stars 302 forks source link

Kivy example does not build #1679

Open FilMarini opened 1 month ago

FilMarini commented 1 month ago

Description

I tried to build the kivy example for Android. An error pops up not allowing to finish the build

What I Did

Following the README, I tried to build the kivy example.

This is what I did

pip3 install buildozer cython
buildozer android debug

And this is what I get (after a while)

[INFO]:    Building bleak for arm64-v8a
[INFO]:    bleak apparently isn't already in site-packages
[INFO]:    Installing bleak into site-packages
[INFO]:    -> directory context /home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/bleak/arm64-v8a__ndk_target_21/bleak
[DEBUG]:   -> running python3 setup.py install -O2 --root=/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/bleakdemo/arm64-v8a --install-lib=.
[DEBUG]:    Traceback (most recent call last):
[DEBUG]:      File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/bleak/arm64-v8a__ndk_target_21/bleak/setup.py", line 6, in <module>
[DEBUG]:        setup(
[DEBUG]:      File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/__init__.py", line 104, in setup
[DEBUG]:        return distutils.core.setup(**attrs)
[DEBUG]:               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[DEBUG]:      File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/_distutils/core.py", line 147, in setup
[DEBUG]:        _setup_distribution = dist = klass(attrs)
[DEBUG]:                                     ^^^^^^^^^^^^
[DEBUG]:      File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/dist.py", line 318, in __init__
[DEBUG]:        self.metadata.version = self._normalize_version(self.metadata.version)
[DEBUG]:                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[DEBUG]:      File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/dist.py", line 354, in _normalize_version
[DEBUG]:        normalized = str(Version(version))
[DEBUG]:                         ^^^^^^^^^^^^^^^^
[DEBUG]:      File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/_vendor/packaging/version.py", line 198, in __init__
[DEBUG]:        raise InvalidVersion(f"Invalid version: '{version}'")
[DEBUG]:    setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'bleak develop branch'
Exception in thread background thread for pid 245972:
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 "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 1634, in wrap
    fn(*rgs, **kwargs)
  File "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 2636, in background_thread
    handle_exit_code(exit_code)
  File "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 2327, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 821, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py install -O2 --root=/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/bleakdemo/arm64-v8a --install-lib=.

  STDOUT:
Traceback (most recent call last):
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/bleak/arm64-v8a__ndk_target_21/bleak/setup.py", line 6, in <module>
    setup(
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/__init__.py", line 104, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/_distutils/core.py", line 147, in setup
    _setup_distribution = dist = klass(attrs)
                                 ^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/dist.py", line 318, in __init__
    self.metadata.version = self._normalize_version(self.metadata.version)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/dist.py", line 354, in _normalize_version
    normalized = str(Version(version))
                     ^^^^^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/_vendor/packaging/version.py", line 198, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'bleak develop branch'

  STDERR:

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1245, in <module>
    main()
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 677, in __init__
    getattr(self, command)(args)
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 104, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 163, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx,
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 504, in build_recipes
    recipe.build_arch(arch)
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 967, in build_arch
    self.install_python_package(arch)
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 983, in install_python_package
    shprint(hostpython, 'setup.py', 'install', '-O2',
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 167, in shprint
    for line in output:
  File "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 877, in __next__
    self.wait()
  File "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 794, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/fmarini/.local/lib/python3.10/site-packages/sh.py", line 821, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py install -O2 --root=/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/python-installs/bleakdemo/arm64-v8a --install-lib=.

  STDOUT:
Traceback (most recent call last):
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/bleak/arm64-v8a__ndk_target_21/bleak/setup.py", line 6, in <module>
    setup(
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/__init__.py", line 104, in setup
    return distutils.core.setup(**attrs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/_distutils/core.py", line 147, in setup
    _setup_distribution = dist = klass(attrs)
                                 ^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/dist.py", line 318, in __init__
    self.metadata.version = self._normalize_version(self.metadata.version)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/dist.py", line 354, in _normalize_version
    normalized = str(Version(version))
                     ^^^^^^^^^^^^^^^^
  File "/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a/build/other_builds/hostpython3/desktop/hostpython3/native-build/Lib/site-packages/setuptools/_vendor/packaging/version.py", line 198, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
setuptools.extern.packaging.version.InvalidVersion: Invalid version: 'bleak develop branch'

  STDERR:

# Command failed: ['/usr/bin/python3', '-m', 'pythonforandroid.toolchain', 'create', '--dist_name=bleakdemo', '--bootstrap=sdl2', '--requirements=python3,kivy,bleak,async_to_sync,async-timeout', '--arch=arm64-v8a', '--copy-libs', '--local-recipes', '/home/fmarini/sink/rp-pico/prova/bleak/bleak/backends/p4android/recipes', '--color=always', '--storage-dir=/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy/.buildozer/android/platform/build-arm64-v8a', '--ndk-api=21', '--ignore-setup-py', '--debug']
# ENVIRONMENT:
#     GJS_DEBUG_TOPICS = 'JS ERROR;JS LOG'
#     SYSTEMD_EXEC_PID = '2449'
#     SESSION_MANAGER = 'local/ThinkPad-X1:@/tmp/.ICE-unix/2408,unix/ThinkPad-X1:/tmp/.ICE-unix/2408'
#     LANG = 'en_US.UTF-8'
#     SSH_AUTH_SOCK = '/run/user/1000/keyring/ssh'
#     XDG_CURRENT_DESKTOP = 'ubuntu:GNOME'
#     LC_MEASUREMENT = 'it_IT.UTF-8'
#     WAYLAND_DISPLAY = 'wayland-0'
#     LC_IDENTIFICATION = 'it_IT.UTF-8'
#     GIO_LAUNCHED_DESKTOP_FILE_PID = '5439'
#     TERMINATOR_DBUS_PATH = '/net/tenshu/Terminator2'
#     XDG_DATA_DIRS = '/usr/local/share/:/usr/share/:/var/lib/snapd/desktop'
#     PWD = '/home/fmarini/sink/rp-pico/prova/bleak/examples/kivy'
#     QT_IM_MODULE = 'ibus'
#     USER = 'fmarini'
#     DESKTOP_SESSION = 'ubuntu'
#     XDG_MENU_PREFIX = 'gnome-'
#     OLDPWD = '/home/fmarini/sink/rp-pico/prova/bleak/examples'
#     GJS_DEBUG_OUTPUT = 'stderr'
#     HOME = '/home/fmarini'
#     TERMINATOR_UUID = 'urn:uuid:5ea1a8df-3184-4bb2-b24f-18726b116857'
#     TERM = 'xterm-256color'
#     DBUS_SESSION_BUS_ADDRESS = 'unix:path=/run/user/1000/bus'
#     XMODIFIERS = '@im=ibus'
#     COLORTERM = 'truecolor'
#     SSH_AGENT_LAUNCHER = 'gnome-keyring'
#     LC_NUMERIC = 'it_IT.UTF-8'
#     _ = '/home/fmarini/.local/bin/buildozer'
#     GTK_MODULES = 'gail:atk-bridge'
#     VTE_VERSION = '6800'
#     JOURNAL_STREAM = '8:10948'
#     XDG_SESSION_DESKTOP = 'ubuntu'
#     QT_ACCESSIBILITY = '1'
#     GNOME_DESKTOP_SESSION_ID = 'this-is-deprecated'
#     MANAGERPID = '2290'
#     LC_TIME = 'it_IT.UTF-8'
#     LOGNAME = 'fmarini'
#     LC_PAPER = 'it_IT.UTF-8'
#     GNOME_SETUP_DISPLAY = ':1'
#     PATH = '/home/fmarini/.buildozer/android/platform/apache-ant-1.9.4/bin:/home/fmarini/sink/rp-pico/prova/bleak/env/bin:/home/fmarini/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/home/fmarini/.local/share/coursier/bin'
#     XDG_RUNTIME_DIR = '/run/user/1000'
#     GNOME_SHELL_SESSION_MODE = 'ubuntu'
#     XDG_SESSION_TYPE = 'wayland'
#     LC_MONETARY = 'it_IT.UTF-8'
#     SHELL = '/usr/bin/zsh'
#     LC_TELEPHONE = 'it_IT.UTF-8'
#     USERNAME = 'fmarini'
#     GIO_LAUNCHED_DESKTOP_FILE = '/usr/share/applications/terminator.desktop'
#     INVOCATION_ID = '718cbe05988842debc45ab2b944ddccd'
#     SHLVL = '1'
#     XAUTHORITY = '/run/user/1000/.mutter-Xwaylandauth.NJBDW2'
#     TERMINATOR_DBUS_NAME = 'net.tenshu.Terminator25ef4b219e3b005583550f2b0f9f990c3'
#     LC_NAME = 'it_IT.UTF-8'
#     DISPLAY = ':0'
#     LC_ADDRESS = 'it_IT.UTF-8'
#     GDMSESSION = 'ubuntu'
#     XDG_SESSION_CLASS = 'user'
#     IBUS_DISABLE_SNOOPER = '1'
#     ZSH = '/home/fmarini/.oh-my-zsh'
#     DEFAULT_USER = 'fmarini'
#     PAGER = 'less'
#     LESS = '-R'
#     LSCOLORS = 'Gxfxcxdxbxegedabagacad'
#     LS_COLORS = 'rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:'
#     PS1 = '(env) %{%f%b%k%}$(build_prompt) '
#     VIRTUAL_ENV = '/home/fmarini/sink/rp-pico/prova/bleak/env'
#     VIRTUAL_ENV_PROMPT = '(env) '
#     PACKAGES_PATH = '/home/fmarini/.buildozer/android/packages'
#     ANDROIDSDK = '/home/fmarini/.buildozer/android/platform/android-sdk'
#     ANDROIDNDK = '/home/fmarini/.buildozer/android/platform/android-ndk-r25b'
#     ANDROIDAPI = '31'
#     ANDROIDMINAPI = '21'
# 
# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

I tried running it from both the develop branch as well as from the latest tag, v0.22.3, and master

FilMarini commented 4 weeks ago

The error is related to this line: https://github.com/hbldh/bleak/blob/develop/bleak/backends/p4android/recipes/bleak/__init__.py#L11

if you change it to 0.20.0 for example, buildozer finishes the build.

Unfortunately, if I run the compiled example on my phone, the app crashes at start. Reading the log, it seems that a significant error could be this one:

FATAL EXCEPTION: main
10-30 10:18:47.401 20466 20466 E AndroidRuntime: Process: com.example.bleuart, PID: 20466
10-30 10:18:47.401 20466 20466 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bleuart/com.example.bleuart.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

Any idea how to solve this? Thanks