Kivy应用程序无法在Android上运行 [英] Kivy application does not work on Android

查看:161
本文介绍了Kivy应用程序无法在Android上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用kivy在适用于Android的Python中编写简单的应用程序.可悲的是,当我启动示例代码时,我仅看到启动屏幕,几秒钟后应用程序完成工作.调试存在很大问题,因为Linux Mint上的adb无法检测到我的设备.

I want write simple application in Python for Android using kivy. Sadly when I start example code I see only splash screen and few second later application finish work. There is a huge problem with debugging because adb on Linux Mint does not detect my device.

有人可以看看我的代码并告诉我为什么吗? 要构建应用程序,我使用buildozer.您还可以看到create_env脚本来检查所有依赖项是否存在.

Can someone look at my code and tell my why? To build application I use buildozer. You can also see create_env script to check all dependencies are there.

最好的问候. 德拉昆

我开始调试我的应用程序.结论:

I started debugging my application. Conclusion:

  • buildozer + python3 + kivy是个坏主意
  • 如果当文本属性为str时我使用kivy.uix.button.Button而不是异常"AttributeError:'str'对象没有属性'decode'"
  • 如果我在文本属性为字节时使用kivy.uix.button.Button而不是异常"ValueError:Button.text仅接受str"

看起来像没有解决方案的循环.有什么想法我应该报告?

It looks like loop with no solution. Some idea when I should report it?

.buildozer/android/platform/build/build/python-installs/pad/android/ init .py"文件中包含异常,因此它看起来不像是kivy和/或buildozer异常.

Exception is in .buildozer/android/platform/build/build/python-installs/pad/android/init.py" file so it does not look like kivy and/or buildozer exception.

推荐答案

我使用了python-for android工具,但遇到了同样的错误.但就我而言,该应用程序根本没有运行-从启动屏幕崩溃.最后,我找到了解决方案.您可以尝试相同的方式.

I've used python-for android tool and faced with the same errors. But in my case, app didn't run at all - crashed from splash screen. Finally, I've found a solution. You can try the same way.

所以我的管道是python3 + python-for-android(p4a工具, python-for- android (来自master分支)+ kivy(1.10.1)

So my pipeline was python3 + python-for-android (p4a tool, python-for-android, from master branch) + kivy (1.10.1)

有一个文件"_android.pyx"用于android构建配方(可用命令p4a recipes查看的可用p4a配方的完整列表).该文件可能由Buildozer使用,并且在APK构建过程中由P4A完全使用.您需要修复它.

There is a file "_android.pyx" for android building recipe (full list of avaliable p4a recipes you can see by command p4a recipes). This file is, possibly, used by Buildozer, and exactly used by P4A during APK building procedure. You need to fix it.

您可以通过以下方式找到它在Ubuntu中的位置(例如):

You may find it's location in Ubuntu (for example) via:

sudo updatedb
locate _android.pyx

它的路径应该类似于:

~/.local/lib/python3.6/site-packages/pythonforandroid/recipes/android/src/android/_android.pyx

应该有一个字符串:

python_act = autoclass(JAVA_NAMESPACE.decode('utf-8') + u'.PythonActivity')

所以您应该更改它-像这样:

so you should change it - something like this:

python_act = autoclass(str(JAVA_NAMESPACE) + u'.PythonActivity'),

或仅使用一些硬代码:

python_act = autoclass("org/kivy/android/PythonActivity")

或者在源中可能还有其他的encode()用法.

Or there might be the other decode() usage in sources.

原因:Python2和Python3之间的差异-在Python 2或3中等效的二进制数据类型上都可以使用encode()方法,但Python 2和3之间的文本数据类型不能始终使用它.因为Python 3中的str没有方法解码功能在Python3中具有不同的实现.更多详细信息在这里: 导入功能 发布p4a的github

The reason: differences between Python2 and Python3 - the decode() method is usable on the equivalent binary data type in either Python 2 or 3, but it can’t be used by the textual data type consistently between Python 2 and 3 because str in Python 3 doesn’t have the method decode function has different realisation in Python3. More details are here: pyporting features issues p4a's github

希望,它将以某种方式帮助您.

Hope, it will help you somehow.

这篇关于Kivy应用程序无法在Android上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆