【问题标题】:Kivy app build successfully using buildozer but crashes when opened on android phoneKivy 应用程序使用 buildozer 成功构建,但在 android 手机上打开时崩溃
【发布时间】:2020-11-02 01:06:58
【问题描述】:

我正在使用 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 解决的 no module found 错误后,该应用程序仍然在我的 Android 手机上崩溃。这是我在运行应用程序时收到的新logcat

【问题讨论】:

  • 贴一下logcat的输出,你贴的好像没有。
  • @inclement 我提供了整个输出的链接。单击链接(日志字)它将带您到保管箱文件
  • 不包含logcat日志。
  • @inclement 在官方文档buildozer.readthedocs.io/en/latest/quickstart.html中明确写到使用该命令时可以将logcat保存到log.txt文件中。所以这意味着 log.txt 内容是我在链接中提供的 logcat 输出
  • logcat 输出是来自设备的日志流。看起来你从来没有收到过任何东西。由于您收到的最后一件事是连接的设备的空列表,您是否真的插入了设备并启用了 USB 调试?

标签: python android kivy kivy-language buildozer


【解决方案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 构建配方才能工作,但我认为目前没有一个(尽管您的问题似乎更笼统地说您根本没有包含它)。

【讨论】:

  • @inclememt 哦,我根本没有注意到那个日志!但这很奇怪,因为我在 buildozer.spec 文件中的要求下包含了 beautifulsoup,正如您在上面的描述中看到的那样。我是否错过了 .spec 文件中的某些内容?我是不是写错了需求?
  • 我不知道,但如果没有 python-for-android 中的构建配方,它仍然可能无法工作。
  • 在将 bs4 放入需求后,我能够解决 no module named error 的问题。该应用程序仍然在我的手机上崩溃。我发布了新的 logcat 输出,看起来我没有任何名为错误的 no 模块了。我很绝望,我不知道为什么应用程序崩溃了
【解决方案2】:

经过几天的调试,我终于找到了错误,这是我在项目中使用的一些第三方库引起的。很明显kivy、buildozer或者python-for-android都解析不了这个(不知道是怎么打包的)。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-28
    • 2021-08-02
    • 2022-10-21
    • 2017-02-14
    • 2022-08-24
    • 2017-12-05
    • 2020-11-04
    • 2020-08-18
    相关资源
    最近更新 更多