Kivy 有史以来我接触最不友好的一个Python框架

开头

最近有个朋友找我帮他看看一个构建Kivy的问题。结果弄了整整一天,连编译环境都有问题,最终也没能编译成功。虽然最后里成功已经很接近了,但
考虑朋友说换成用HTML做了,就没有继续折腾Kivy了。

部署

刚开始,我说想快点帮他解决,就打算直接在Kivy官网找官方的Docker镜像下载了。后来,下了好几个镜像,官方的,非官方的
结果都有各种各样的问题,跑不通。

后面就放弃Docker了,直接在本地环境搭建环境。在运行buildozer -v android debug 的时候,报错:

1
'sdkmanager not installed'

后面才发现需装一个Android的SDK (Android Studio ),这我在官方文档上都看到啊。。真是无语哎

  • 相关报错信息:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    Original exception:
    ===================
    Traceback (most recent call last):
    File "/Users/xifeng.li/.local/lib/python3.7/site-packages/sh.py", line 2076, in __init__
    os.execve(cmd[0], cmd, ca["env"])
    OSError: [Errno 8] Exec format error: b'/Users/xifeng.li/opt/test_kivy/app/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3'
    # Command failed: /Users/xifeng.li/opt/anaconda3/bin/python -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=python3,kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/Users/xifeng.li/opt/test_kivy/app/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21
    # ENVIRONMENT:
    # TERM_PROGRAM = 'iTerm.app'
    # PYENV_ROOT = '/Users/xifeng.li/.pyenv'
    # TERM = 'xterm-256color'
    # SHELL = '/bin/bash'
    # CLICOLOR = 'Yes'
    # TMPDIR = '/var/folders/5_/r_bbpkqj2t126yjr97zgbvshnb19df/T/'
    # CONDA_SHLVL = '1'
    # CONDA_PROMPT_MODIFIER = '(base) '
    # TERM_PROGRAM_VERSION = '3.3.9'
    # OLDPWD = '/Users/xifeng.li/Library/Android/sdk/tools/bin'
    # TERM_SESSION_ID = 'w0t3p0:A097B1EA-1572-46C1-847B-DC60F03F9BCF'
    # USER = 'xifeng.li'
    # COMMAND_MODE = 'unix2003'
    # CONDA_EXE = '/Users/xifeng.li/opt/anaconda3/bin/conda'
    # SSH_AUTH_SOCK = '/private/tmp/com.apple.launchd.xatnkbYTCt/Listeners'
    # __CF_USER_TEXT_ENCODING = '0x2AB0A5AE:0x0:0x0'
    # _CE_CONDA = ''
    # PATH = '/Users/xifeng.li/.buildozer/android/platform/apache-ant-1.9.4/bin:/Users/xifeng.li/Library/Android/sdk/sdkmanager:/Users/xifeng.li/Library/Android/sdk/tools:/Users/xifeng.li/.pyenv/bin:/Users/xifeng.li/opt/anaconda3/bin:/Users/xifeng.li/opt/anaconda3/condabin:/Users/xifeng.li/.pyenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/xifeng.li/Library/Python/2.7/bin:/Users/xifeng.li/.local/bin'
    # LaunchInstanceID = 'D7D5D23B-AE28-49F3-80C1-63F519A6608F'
    # CONDA_PREFIX = '/Users/xifeng.li/opt/anaconda3'
    # PWD = '/Users/xifeng.li/opt/test_kivy/app'
    # JAVA_HOME = '/Library/Java/JavaVirtualMachines/jdk1.8.0_231.jdk/Contents/Home'
    # ANDROID_SDK = '/Users/xifeng.li/Library/Android/sdk'
    # ITERM_PROFILE = 'Default'
    # XPC_FLAGS = '0x0'
    # _CE_M = ''
    # XPC_SERVICE_NAME = '0'
    # SHLVL = '1'
    # HOME = '/Users/xifeng.li'
    # COLORFGBG = '15;0'
    # LC_TERMINAL_VERSION = '3.3.9'
    # LS_OPTIONS = '--color=auto'
    # ITERM_SESSION_ID = 'w0t3p0:A097B1EA-1572-46C1-847B-DC60F03F9BCF'
    # CONDA_PYTHON_EXE = '/Users/xifeng.li/opt/anaconda3/bin/python'
    # LOGNAME = 'xifeng.li'
    # LC_CTYPE = 'UTF-8'
    # CONDA_DEFAULT_ENV = 'base'
    # LC_TERMINAL = 'iTerm2'
    # SECURITYSESSIONID = '186a6'
    # COLORTERM = 'truecolor'
    # _ = '/Users/xifeng.li/.local/bin/buildozer'
    # PACKAGES_PATH = '/Users/xifeng.li/.buildozer/android/packages'
    # ANDROIDSDK = '/Users/xifeng.li/.buildozer/android/platform/android-sdk'
    # ANDROIDNDK = '/Users/xifeng.li/.buildozer/android/platform/android-ndk-r19c'
    # ANDROIDAPI = '27'
    # 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
    (base) XifengLideMacBook-Pro:app xifeng.li$ /Users/xifeng.li/opt/anaconda3/bin/python -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=python3,kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/Users/xifeng.li/opt/test_kivy/app/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21
    /Users/xifeng.li/opt/anaconda3/lib/python3.7/site-packages/pythonforandroid/toolchain.py:84: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp
    [INFO]: Will compile for the following archs: armeabi-v7a
    [ERROR]: Build failed: Android SDK dir was not specified, exiting.

Reference

https://github.com/diegodukao/docker-python3-kivy-buildozer
https://stackoverflow.com/questions/65724724/while-building-kivy-app-sdkmanager-not-installed
https://developer.android.com/studio#downloads
https://hub.docker.com/r/kivy/buildozer