Kivy 应用程序使用 buildozer 成功构建,但在 Android 手机上打开时崩溃

问题描述 投票:0回答:3

我正在使用 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

这是log文件

此外,以下是我对默认 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

#

编辑

这是 logcat

的输出

Edit2:解决了@inclement 提出的“没有找到模块”错误后,该应用程序仍然在我的 Android 手机上崩溃。这是我运行应用程序时收到的新 logcat

python android kivy kivy-language buildozer
3个回答
1
投票
由于应用程序已成功启动,请在 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 构建配方才能工作,但我认为目前还没有(尽管你的问题似乎更普遍,你根本没有包含它)。


0
投票
经过几天的调试,我终于找到了错误,这是我在项目中使用的一些第三方库引起的。显然,kivy、buildozer 或 python-for-android 无法解析这个(我不知道打包是如何完成的)。

如果有人遇到此问题,我强烈建议使用模拟器进行调试,而不是依赖 logcat。就我而言,logcat 毫无用处。它没有告诉我任何有关错误的信息。

我需要一步一步尝试删除依赖项,直到发现错误。 @inclement 的回答和评论也很有帮助。


0
投票
我遇到了问题

© www.soinside.com 2019 - 2024. All rights reserved.