python - Kivy 应用程序使用 buildozer 成功构建,但在 android 手机上打开时崩溃
问题描述
我正在使用 kivy 构建一个应用程序,它可以在我的 Linux 笔记本电脑上完美运行。我使用buildozer为 android 构建应用程序,日志没有显示任何错误。完成后,会在 bin 文件夹中创建 apk 文件。
然后我复制apk文件并将其粘贴到我的手机存储中,然后安装该应用程序。
当我打开应用程序时,它会显示 kivy 徽标并正在加载......但随后它崩溃了!我尝试了一整天来寻找解决方案,但我无法实现。
我在谷歌搜索问题时发现了这个命令,它应该有助于调试,但我无法理解输出!:
buildozer android logcat
这是我运行此命令时打印的日志
# Ensure build layout
# Check configuration tokens
# Run 'dpkg --version'
# Cwd None
Debian 'dpkg' package management program version 1.19.0.5 (amd64).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
# Search for Git (git)
# -> found at /usr/bin/git
# Search for Cython (cython)
# -> found at /home/nidhal/.local/bin/cython
# Search for Java compiler (javac)
# -> found at /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
# Search for Java keytool (keytool)
# -> found at /usr/lib/jvm/java-11-openjdk-amd64/bin/keytool
# Run '/home/nidhal/.buildozer/android/platform/android-sdk/platform-tools/adb devices'
# Cwd None
List of devices attached
nidhal@nidhal-Latitude-E6320:~/Desktop/my_code/deep-translator-app$ clear
nidhal@nidhal-Latitude-E6320:~/Desktop/my_code/deep-translator-app$ buildozer android logcat
# Check configuration tokens
# Ensure build layout
# Check configuration tokens
# Run 'dpkg --version'
# Cwd None
Debian 'dpkg' package management program version 1.19.0.5 (amd64).
This is free software; see the GNU General Public License version 2 or
later for copying conditions. There is NO warranty.
# Search for Git (git)
# -> found at /usr/bin/git
# Search for Cython (cython)
# -> found at /home/nidhal/.local/bin/cython
# Search for Java compiler (javac)
# -> found at /usr/lib/jvm/java-11-openjdk-amd64/bin/javac
# Search for Java keytool (keytool)
# -> found at /usr/lib/jvm/java-11-openjdk-amd64/bin/keytool
# Run '/home/nidhal/.buildozer/android/platform/android-sdk/platform-tools/adb devices'
# Cwd None
List of devices attached
此外,我尝试在使用以下命令运行构建时存储整个日志:
buildozer android debug deploy run logcat > log.txt
这是日志文件
此外,以下是我对默认 buildozer.spec 文件所做的更改:
[app]
# (str) Title of your application
title = Overall Translator
# (str) Package name
package.name = overallTranslator
# (str) Package domain (needed for android/ios packaging)
package.domain = org.nidhal.overallTranslator
# (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,ttf
# (list) List of inclusions using pattern matching
source.include_patterns = assets/*,images/*.png, font/*.ttf
# (list) Source files to exclude (let empty to not exclude anything)
source.exclude_exts = spec, txt, md, gitignore
# (list) List of directory to exclude (let empty to not exclude anything)
source.exclude_dirs = tests, bin, venv
# (list) List of exclusions using pattern matching
#source.exclude_patterns = license,images/*/*.jpg
# (str) Application versioning (method 1)
#version = 0.1
# (str) Application versioning (method 2)
version.regex = __version__ = ['"](.*)['"]
version.filename = %(source.dir)s/main.py
# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = hostpython3==3.7.8,python3==3.7.8,kivy==1.11.1, beautifulsoup4, bs4, certifi,chardet,docutils, future, idna, Kivy-Garden, Pygments, requests, six, soupsieve, urllib3, deep-translator, arabic-reshaper, python-bidi, openssl
# (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes
# requirements.source.kivy = ../../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, sensorLandscape, portrait or all)
orientation = portrait
# (list) List of service to declare
#services = NAME:ENTRYPOINT_TO_PY,NAME2:ENTRYPOINT2_TO_PY
#
# OSX Specific
#
#
# author = © Copyright Info
# change the major version of python used by the app
osx.python_version = 3
# Kivy version to use
osx.kivy_version = 1.9.1
#
编辑
Edit2:在解决了@inclement 解决的 no module found 错误后,该应用程序仍然在我的 android 手机上崩溃。这是我运行应用程序时收到的新logcat
解决方案
由于应用程序已成功启动,请在 logcat 中查找包含字符串“python”的行。这将揭示回溯:
07-13 00:47:44.658 27252 27350 I python : [INFO ] [Window ] auto add sdl2 input provider
07-13 00:47:44.658 27252 27350 I python : [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
07-13 00:47:44.660 27252 27350 I python : Traceback (most recent call last):
07-13 00:47:44.660 27252 27350 I python : File "/home/nidhal/Desktop/my_code/deep-translator-app/.buildozer/android/app/main.py", line 5, in <module>
07-13 00:47:44.661 27252 27350 I python : File "/home/nidhal/Desktop/my_code/deep-translator-app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/overalltranslator/deep_translator/__init__.py", line 3, in <module>
07-13 00:47:44.661 27252 27350 I python : File "/home/nidhal/Desktop/my_code/deep-translator-app/.buildozer/android/platform/build-armeabi-v7a/build/python-installs/overalltranslator/deep_translator/google_trans.py", line 5, in <module>
07-13 00:47:44.661 27252 27350 I python : ModuleNotFoundError: No module named 'bs4'
07-13 00:47:44.661 27252 27350 I python : Python for android ended.
Beautifulsoup4 需要一个 python-for-android 构建配方才能工作,但我认为目前没有一个(尽管你的问题似乎更笼统地说你根本没有包括它)。
推荐阅读
- android - 无法从 Firebase 检索数据
- android - 为什么微调器项目样式有效,但微调器下拉项目样式失败?
- javascript - Edge 中的 OIDC 客户端问题
- javascript - ASP.NET 和 C#:在键入和粘贴时从 asp.TextBox 中删除空格
- firebase - 编译的 Jar 不断抛出: SynchronizationContext 中未捕获的异常
- java - 在线程上用java播放音乐
- java - 如何处理无效输入
- sql - 如何在 IF 条件下检查 Query 是否为空?
- python - 如何根据模式从 2D NumPy 数组中提取 2D NumPy 子数组?
- r - 删除重复的行,选择要保留的特定值