使用 Python-For-Android 将 Python 脚本导出到 Android 可执行文件 (.apk) [英] Export a Python script to an Android executable (.apk) with Python-For-Android

查看:40
本文介绍了使用 Python-For-Android 将 Python 脚本导出到 Android 可执行文件 (.apk)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用适用于 Android 的 Python 将我的 Python 脚本导出到 Android 可执行文件 (.apk).

i'm trying to export my Python script to an Android executable (.apk) with Python for Android.

http://python-for-android.readthedocs.org/en/latest/toolchain/#how-does-it-work

https://github.com/kivy/python-for-android/

在发行版中(默认为 dist/default),你有一个工具命名为 build.py.这是将为您创建 APK 的脚本

Inside the distribution (dist/default by default), you have a tool named build.py. This is the script that will create the APK for you

我已按照所有步骤操作,但有一个问题:创建的 dist/default 文件夹不包含任何 build.py.它是空的.

I have followed all the steps, but I have a problem : the dist/default folder created doesn't contain any build.py. It's empty.

有什么问题吗?我该如何解决?请帮忙!

What's the problem ? How do I resolve it ? Help, please !

推荐答案

所以,基本上,您正在使用 buildozer 并且它现在正在工作.再次查看 buildozer.spec 文件.应该有以下几行:

So, basically, you're using buildozer and it's working now. Look in the buildozer.spec file again. There should be the lines:

# (str) Application versioning (method 1)
version.regex = __version__ = '(.*)'
version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
# version = 1.2.0

你想做的,我相信(因为我必须这样做),就是把它们改成这样:

what you want to do, I believe( because I had to do this ), is change them to this:

# (str) Application versioning (method 1)
# version.regex = __version__ = '(.*)'
# version.filename = %(source.dir)s/main.py

# (str) Application versioning (method 2)
version = 1.2.0

看我已经注释掉了顶部的两行,并取消了底部的注释.(我自己还没有费心更改'1.2.0',所以不知道这是否有区别.它不应该.)问题似乎是 buildozer 在您的 py 文件中查找一行,__version__ = something,找不到就报错.我尝试将此行添加到我的 python 中,但它仍然不起作用.然而,这种改变确实奏效了.

see I have commented out two lines at the top, and uncommented the bottom line. (I haven't bothered changing the '1.2.0' yet myself, so don't know if that makes a difference. It shouldn't.) The problem seems to be that buildozer looks for a line in your py file, __version__ = something, and there is an error when it doesn't find it. I tried adding this line to my python, but it still didn't work. This change however, did work.

此外,尝试在启用详细信息的情况下运行您的构建,以便您可以准确查看导致任何错误的原因,例如:

Also, try running your build with verbose on, so you can see exactly what's causing any errors, for example:

sudo buildozer --verbose android debug deploy run

这篇关于使用 Python-For-Android 将 Python 脚本导出到 Android 可执行文件 (.apk)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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