buildozer:因“env”崩溃:env 必须是一个字典

buildozer:因“env”崩溃:env 必须是一个字典

错误是“env”:env 必须是字典。我相信我已经升级了 buildozer 和我的 env。我的 buildozer 是使用 pip3 安装的,我的代码适用于 python 3。另外,我在源代码中使用了模块 plyer,我不知道是否如此,但如果我只是构建 kivy,则不会出现错误。

请提供一些建议、解决方案或反馈!

下面是我的 main.py、buildozer.spec 和日志(由于正文大小限制,我删除了一些)。

主要文件:

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.properties import StringProperty

from plyer import sms

Builder.load_string('''
<SmsInterface>:
    orientation: 'vertical'
    BoxLayout:
        size_hint_y: None
        height: sp(30)
        Label:
            text: 'Recipient:'
        TextInput:
            id: recipient
            multiline: False
            on_text_validate: message.focus = True
    BoxLayout:
        Label:
            text: 'Message:'
        TextInput:
            id: message
    IntentButton:
        sms_recipient: recipient.text
        sms_message: message.text
        text: 'Send SMS'
        size_hint_y: None
        height: sp(40)
        on_release: self.send_sms()
''')


class SmsInterface(BoxLayout):
    pass


class IntentButton(Button):
    sms_recipient = StringProperty()
    sms_message = StringProperty()

    def send_sms(self, *args):
        sms.send(recipient=self.sms_recipient, message=self.sms_message)


class SmsApp(App):
    def build(self):
        return SmsInterface()

    def on_pause(self):
        return True


if __name__ == "__main__":
    SmsApp().run()

buildozer.spec:

[app]

# (str) Title of your application
title = Plyer sms Test

# (str) Package name
package.name = plyersms

# (str) Package domain (needed for android/ios packaging)
package.domain = org.test

# (str) Source code where the main.py live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas

# (list) Source files to exclude (let empty to not exclude anything)
#source.exclude_exts = spec

# (list) List of directory to exclude (let empty to not exclude anything)
#source.exclude_dirs = tests, bin

# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg

# (str) Application versioning (method 1)
#version.regex = __version__ = '(.*)'
#version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
version = 0.1

# (list) Application requirements
requirements = plyer,kivy

# (list) Garden requirements
#garden_requirements =

# (str) Presplash of the application
#presplash.filename = %(source.dir)s/data/presplash.png

# (str) Icon of the application
#icon.filename = %(source.dir)s/data/icon.png

# (str) Supported orientation (one of landscape, portrait or all)
orientation = portrait

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0


#
# Android specific
#

# (list) Permissions
android.permissions = SEND_SMS

# (int) Android API to use
#android.api = 14

# (int) Minimum API required (8 = Android 2.2 devices)
#android.minapi = 8

# (int) Android SDK version to use
#android.sdk = 21

# (str) Android NDK version to use
#android.ndk = 9c

# (bool) Use --private data storage (True) or --dir public storage (False)
#android.private_storage = True

# (str) Android NDK directory (if empty, it will be automatically downloaded.)
#android.ndk_path =

# (str) Android SDK directory (if empty, it will be automatically downloaded.)
#android.sdk_path =

# (str) python-for-android git clone directory (if empty, it will be automatically cloned from github)
#android.p4a_dir =

# (str) Android entry point, default is ok for Kivy-based app
#android.entrypoint = org.renpy.android.PythonActivity

# (list) List of Java .jar files to add to the libs so that pyjnius can access
# their classes. Don't add jars that you do not need, since extra jars can slow
# down the build process. Allows wildcards matching, for example:
# OUYA-ODK/libs/*.jar
#android.add_jars = foo.jar,bar.jar,path/to/more/*.jar

# (list) List of Java files to add to the android project (can be java or a
# directory containing the files)
#android.add_src =

# (str) python-for-android branch to use, if not master, useful to try
# not yet merged features.
#android.branch = master

# (str) OUYA Console category. Should be one of GAME or APP
# If you leave this blank, OUYA support will not be enabled
#android.ouya.category = GAME

# (str) Filename of OUYA Console icon. It must be a 732x412 png image.
#android.ouya.icon.filename = %(source.dir)s/data/ouya_icon.png

# (str) XML file to include as an intent filters in <activity> tag
#android.manifest.intent_filters =

# (list) Android additionnal libraries to copy into libs/armeabi
#android.add_libs_armeabi = libs/android/*.so

# (bool) Indicate whether the screen should stay on
# Don't forget to add the WAKE_LOCK permission if you set this to True
#android.wakelock = False

# (list) Android application meta-data to set (key=value format)
#android.meta_data =

# (list) Android library project to add (will be added in the
# project.properties automatically.)
#android.library_references =

#
# iOS specific
#

# (str) Name of the certificate to use for signing the debug version
# Get a list of available identities: buildozer ios list_identities
#ios.codesign.debug = "iPhone Developer: <lastname> <firstname> (<hexstring>)"

# (str) Name of the certificate to use for signing the release version
#ios.codesign.release = %(ios.codesign.debug)s


[buildozer]

# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2


# -----------------------------------------------------------------------------
# List as sections
#
# You can define all the "list" as [section:key].
# Each line will be considered as a option to the list.
# Let's take [app] / source.exclude_patterns.
# Instead of doing:
#
#     [app]
#     source.exclude_patterns = license,data/audio/*.wav,data/images/original/*
#
# This can be translated into:
#
#     [app:source.exclude_patterns]
#     license
#     data/audio/*.wav
#     data/images/original/*
#


# -----------------------------------------------------------------------------
# Profiles
#
# You can extend section / key with a profile
# For example, you want to deploy a demo version of your application without
# HD content. You could first change the title to add "(demo)" in the name
# and extend the excluded directories to remove the HD content.
#
#     [app@demo]
#     title = My Application (demo)
#
#     [app:source.exclude_patterns@demo]
#     images/hd/*
#
# Then, invoke the command line with the "demo" profile:
#
#     buildozer --profile demo android debug

日志:

buildozer android debug deploy run

[INFO]:    Copying pyjnius java class to classes build dir
[INFO]:    -> directory context /home/yd/Desktop/test/.buildozer/android/platform/build-armeabi-v7a/build/other_builds/pyjnius-python3-sdl2/armeabi-v7a__ndk_target_21/pyjnius
[INFO]:    -> running cp -a jnius/src/org /home/yd/D...(and 84 more)
[INFO]:    <- directory context /home/yd/Desktop/test/.buildozer/android/platform/python-for-android
[INFO]:    Postbuilding android for armeabi-v7a
[INFO]:    Postbuilding kivy for armeabi-v7a
[INFO]:    # Installing pure Python modules
[INFO]:    *** PYTHON PACKAGE / PROJECT INSTALL STAGE ***
[INFO]:    The requirements (certifi, plyer) don't have recipes, attempting to install them with pip
[INFO]:    If this fails, it may mean that the module has compiled components and needs a recipe.
[INFO]:    -> directory context /home/yd/Desktop/test/.buildozer/android/platform/build-armeabi-v7a/build
[INFO]:    -> running virtualenv --python=python3 venv
[INFO]:    Upgrade pip to latest version                                       
[INFO]:    -> running bash -c source venv/bin/activat...(and 23 more)
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1199, in <module>
    main()
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/entrypoints.py", line 18, in main
    ToolchainCL()
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 671, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 155, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 209, in build_dist_from_args
    args, "ignore_setup_py", False
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 605, in build_recipes
    ignore_setup_py=ignore_project_setup_py
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 791, in run_pymodules_install
    ), _env=copy.copy(base_env))
  File "/home/yd/Desktop/test/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 179, in shprint
    output = command(*args, **kwargs)
  File "/home/yd/.local/lib/python3.6/site-packages/sh.py", line 1474, in __call__
    extracted_call_args, kwargs = self._extract_call_args(kwargs)
  File "/home/yd/.local/lib/python3.6/site-packages/sh.py", line 1377, in _extract_call_args
    raise TypeError("Invalid special arguments:\n\n%s\n" % exc_msg)
TypeError: Invalid special arguments:

  'env': env must be a dict. Got environ({'GJS_DEBUG_TOPICS': 'JS ERROR;JS LOG', 'LESSOPEN': '| /usr/bin/lesspipe %s', 'USER': 'yd', 'TEXTDOMAIN': 'im-config', 'XDG_SEAT': 'seat0', 'SSH_AGENT_PID': '1163', 'XDG_SESSION_TYPE': 'x11', 'SHLVL': '1', 'QT4_IM_MODULE': 'xim', 'HOME': '/home/yd', 'OLDPWD': '/home/yd/Desktop', 'DESKTOP_SESSION': 'ubuntu', 'GNOME_SHELL_SESSION_MODE': 'ubuntu', 'GTK_MODULES': 'gail:atk-bridge', 'ANDROIDMINAPI': '21', 'DBUS_SESSION_BUS_ADDRESS': 'unix:path=/run/user/1000/bus', 'COLORTERM': 'truecolor', 'IM_CONFIG_PHASE': '2', 'LOGNAME': 'yd', 'GTK_IM_MODULE': 'ibus', '_': '/home/yd/.local/bin/buildozer', 'ANDROIDAPI': '27', 'USERNAME': 'yd', 'XDG_SESSION_ID': '1', 'TERM': 'xterm-256color', 'GNOME_DESKTOP_SESSION_ID': 'this-is-deprecated', 'ANDROIDNDK': '/home/yd/.buildozer/android/platform/android-ndk-r19b', 'WINDOWPATH': '1', 'PATH': '/home/yd/.buildozer/android/platform/android-ndk-r19b/toolchains/llvm/prebuilt/linux-x86_64/bin:/home/yd/.buildozer/android/platform/android-ndk-r19b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86/bin/:/home/yd/.buildozer/android/platform/android-ndk-r19b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/:/home/yd/.buildozer/android/platform/android-ndk-r19b:/home/yd/.buildozer/android/platform/android-sdk/tools:/home/yd/.buildozer/android/platform/apache-ant-1.9.4/bin:/home/yd/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin', 'SESSION_MANAGER': 'local/COMPUTER:@/tmp/.ICE-unix/1027,unix/COMPUTER:/tmp/.ICE-unix/1027', 'XDG_MENU_PREFIX': 'gnome-', 'GNOME_TERMINAL_SCREEN': '/org/gnome/Terminal/screen/32290487_4474_4053_b800_c94f4e7d0d39', 'XDG_RUNTIME_DIR': '/run/user/1000', 'DISPLAY': ':0', 'LANG': 'en_US.UTF-8', 'XDG_CURRENT_DESKTOP': 'ubuntu:GNOME', 'ANDROIDSDK': '/home/yd/.buildozer/android/platform/android-sdk', '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:*.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:*.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:', 'XDG_SESSION_DESKTOP': 'ubuntu', 'XMODIFIERS': '@im=ibus', 'GNOME_TERMINAL_SERVICE': ':1.62', 'XAUTHORITY': '/run/user/1000/gdm/Xauthority', 'SSH_AUTH_SOCK': '/run/user/1000/keyring/ssh', 'SHELL': '/bin/bash', 'QT_ACCESSIBILITY': '1', 'GDMSESSION': 'ubuntu', 'PACKAGES_PATH': '/home/yd/.buildozer/android/packages', 'LESSCLOSE': '/usr/bin/lesspipe %s %s', 'TEXTDOMAINDIR': '/usr/share/locale/', 'GJS_DEBUG_OUTPUT': 'stderr', 'GPG_AGENT_INFO': '/run/user/1000/gnupg/S.gpg-agent:0:1', 'XDG_VTNR': '1', 'QT_IM_MODULE': 'xim', 'PWD': '/home/yd/Desktop/test/.buildozer/android/platform/python-for-android', 'CLUTTER_IM_MODULE': 'xim', 'XDG_DATA_DIRS': '/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop', 'XDG_CONFIG_DIRS': '/etc/xdg/xdg-ubuntu:/etc/xdg', 'VTE_VERSION': '5202', 'PYTHONPATH': '/home/yd/Desktop/test/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/plyersms'})

# Command failed: /usr/bin/python3 -m pythonforandroid.toolchain create --dist_name=plyersms --bootstrap=sdl2 --requirements=plyer,kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/home/yd/Desktop/test/.buildozer/android/platform/build-armeabi-v7a" --ndk-api=21
# ENVIRONMENT:
#     CLUTTER_IM_MODULE = 'xim'
#     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:*.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:*.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:'
#     LESSCLOSE = '/usr/bin/lesspipe %s %s'
#     XDG_MENU_PREFIX = 'gnome-'
#     LANG = 'en_US.UTF-8'
#     DISPLAY = ':0'
#     GNOME_SHELL_SESSION_MODE = 'ubuntu'
#     COLORTERM = 'truecolor'
#     USERNAME = 'yd'
#     XDG_VTNR = '1'
#     SSH_AUTH_SOCK = '/run/user/1000/keyring/ssh'
#     XDG_SESSION_ID = '1'
#     USER = 'yd'
#     DESKTOP_SESSION = 'ubuntu'
#     QT4_IM_MODULE = 'xim'
#     TEXTDOMAINDIR = '/usr/share/locale/'
#     GNOME_TERMINAL_SCREEN = '/org/gnome/Terminal/screen/32290487_4474_4053_b800_c94f4e7d0d39'
#     PWD = '/home/yd/Desktop/test'
#     HOME = '/home/yd'
#     TEXTDOMAIN = 'im-config'
#     SSH_AGENT_PID = '1163'
#     QT_ACCESSIBILITY = '1'
#     XDG_SESSION_TYPE = 'x11'
#     XDG_DATA_DIRS = '/usr/share/ubuntu:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop'
#     XDG_SESSION_DESKTOP = 'ubuntu'
#     GJS_DEBUG_OUTPUT = 'stderr'
#     GTK_MODULES = 'gail:atk-bridge'
#     WINDOWPATH = '1'
#     TERM = 'xterm-256color'
#     SHELL = '/bin/bash'
#     VTE_VERSION = '5202'
#     QT_IM_MODULE = 'xim'
#     XMODIFIERS = '@im=ibus'
#     IM_CONFIG_PHASE = '2'
#     XDG_CURRENT_DESKTOP = 'ubuntu:GNOME'
#     GPG_AGENT_INFO = '/run/user/1000/gnupg/S.gpg-agent:0:1'
#     GNOME_TERMINAL_SERVICE = ':1.62'
#     XDG_SEAT = 'seat0'
#     SHLVL = '1'
#     GDMSESSION = 'ubuntu'
#     GNOME_DESKTOP_SESSION_ID = 'this-is-deprecated'
#     LOGNAME = 'yd'
#     DBUS_SESSION_BUS_ADDRESS = 'unix:path=/run/user/1000/bus'
#     XDG_RUNTIME_DIR = '/run/user/1000'
#     XAUTHORITY = '/run/user/1000/gdm/Xauthority'
#     XDG_CONFIG_DIRS = '/etc/xdg/xdg-ubuntu:/etc/xdg'
#     PATH = '/home/yd/.buildozer/android/platform/apache-ant-1.9.4/bin:/home/yd/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin'
#     GJS_DEBUG_TOPICS = 'JS ERROR;JS LOG'
#     SESSION_MANAGER = 'local/COMPUTER:@/tmp/.ICE-unix/1027,unix/COMPUTER:/tmp/.ICE-unix/1027'
#     LESSOPEN = '| /usr/bin/lesspipe %s'
#     GTK_IM_MODULE = 'ibus'
#     OLDPWD = '/home/yd/Desktop'
#     _ = '/home/yd/.local/bin/buildozer'
#     PACKAGES_PATH = '/home/yd/.buildozer/android/packages'
#     ANDROIDSDK = '/home/yd/.buildozer/android/platform/android-sdk'
#     ANDROIDNDK = '/home/yd/.buildozer/android/platform/android-ndk-r19b'
#     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

答案1

我也遇到了同样的问题,通过对一些 buildozer 代码进行一些小的调整,我能够解决这个问题:

  1. 导航到你的应用程序目录
  2. CD 至:.buildozer/android/platform/python-for-android/pythonforandroid
  3. 打开build.py
  4. 在第 791、797 和 841 行,您应该看到_env=copy.copy(base_env)。将所有实例替换为_env=dict(copy.copy(base_env))

因此,它看起来应该像这样: 图片 1 图片 2

然后,正常保存并重建。祝你好运!

相关内容