p4a android kivy,Kivy application does not work on Android

问题

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.

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.

Best regards.

Draqun

EDIT:

I started debugging my application. Conclusion:

buildozer + python3 + kivy is a bad idea

if I use kivy.uix.button.Button when text attribute is str than I got exception "AttributeError: 'str' object has no attribute 'decode'"

if I use kivy.uix.button.Button when text attribute is bytes than I got exception "ValueError: Button.text accept only str"

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

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.

回答1:

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.

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

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.

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

sudo updatedb

locate _android.pyx

It's path should be something like:

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

There should be a string:

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'),

or just use some hardcode:

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

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

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.

来源:https://stackoverflow.com/questions/55130751/kivy-application-does-not-work-on-android

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值