问题描述
我已经用python 3和kivy编写了一个小程序.现在,我想使用buildozer构建.apk,并在我的Android手机上测试该应用.一切正常,我能够在手机上安装该应用程序,但该应用程序在启动时崩溃了.
I have written a little program in python 3 and kivy. Now I want to build an .apk using buildozer and test the app on my android phone. Everything worked and I was able to install the app on the phone but the app crashed on startup.
错误日志显示,apk的python环境是python 2.7而不是3.因此,我的问题是:是否有可能在Android上使用python 3环境用buildozer构建apk?还是我必须在python2中重写应用程序?
The error log revealed, that the python enviroment of the apk was python 2.7 instead of 3.My question is therefore: Is it possible to build an apk with buildozer using a python 3 enviroment on android? Or do I have to rewrite the app in python2? Is there perhaps a possible hack to force buildozer to use python3?
我遵循了inclement建议的步骤,并收到以下错误:
I followed the steps suggested by inclement and got the following error:
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 747, in <module>
main()
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 744, in main
ToolchainCL()
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 323, in __init__
getattr(self, args.command)(unknown)
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 105, in wrapper_func
build_dist_from_args(ctx, dist, dist_args)
File "/home/micha/python/ZugGit/ZugAppFahrt/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 142, in build_dist_from_args
build_recipes(build_order, python_modules, ctx)
File "pythonforandroid/build.py", line 560, in build_recipes
recipe.build_arch(arch)
File "pythonforandroid/recipe.py", line 910, in build_arch
self.build_cython_components(arch)
File "pythonforandroid/recipe.py", line 919, in build_cython_components
command = sh.Command('python{}'.format(self.ctx.python_recipe.version))
File "/usr/lib/python2.7/site-packages/sh.py", line 788, in __init__
raise CommandNotFound(path)
sh.CommandNotFound: python3.5
# Command failed: python -m pythonforandroid.toolchain create --dist_name=zugFart --bootstrap=sdl2 --requirements=kivy==1.9.1,python3crystax --arch armeabi-v7a --copy-libs
这似乎是一个永无止境的故事.安装python3.5后,我遇到了此错误:
Edit 2: This seems to be a never ending story. With python3.5 installed I ran into this error:
collect2: error: ld returned 1 exit status
error: command 'arm-linux-androideabi-gcc' failed with exit status 1
随着我过去从一个错误到另一个错误的发展,将代码更改为python2.7会更聪明,但是现在我投入了很多时间,我只想最终实现它. :-)
With the time I used to advance from error to error it would be much smarter to simply change the code to python2.7 but now that I have so much time invested I just want to finally make it. :-)
那么有人有解决这个问题的想法吗?
So does somebody have an idea how to solve this issue?
最后我终于投降了,并更改了代码以与python 2.7一起使用.在此过程中,我得到了一个很好的建议:如果您使用未来,则必须将其添加到buildozer文件的要求中.否则,应用程序在启动时会崩溃,并显示空模块"错误消息.
Last I finally surrendered and changed my code to work with python 2.7. A good advice I have overseen during this process: If you using futures it is mandatory to add it to the requirements of the buildozer file. Otherwise the app crash on start with the "empty module" error message.
现在我的应用程序可以在电话上工作了,我终于很高兴:-)感谢努力帮助我解决问题的人.
Now that my app works on the phone I'm finally happy :-) Thanks to inclement trying to help me with my problem.
推荐答案
我不确定buildozer是否具有适用于python3的构建选项,但python-for-android实验性地支持它.您可以通过从其master分支安装buildozer并使用android_new
目标(buildozer android_new debug
)来使用新版本的python-for-android.如果buildozer可以使用其python3选项,则需要在需求中添加python3crystax
(如果存在,请替换python2),手动下载CrystaX NDK,然后将buildozer的NDK path选项设置为指向它.可能还需要在需求中写kivy==1.9.1
而不是仅仅写kivy
.
I'm not sure if buildozer has a build option for python3 yet, but python-for-android supports it experimentally. You can use the new version of python-for-android by installing buildozer from its master branch and using the android_new
target (buildozer android_new debug
). If buildozer will work with its python3 option, you'd need to add python3crystax
in the requirements (replace python2 if it's there), download the CrystaX NDK manually, and set buildozer's NDK path option to point to it. It might also be necessary to write kivy==1.9.1
in the requirements rather than just kivy
.
Python3构建仍在开发中,以具有python2的所有功能,并且需要进行一些清理,包括修剪包含的文件并进行更多压缩.尽管大多数食谱都无法使用某些食谱,但python3尚无法使用.
Python3 builds are still in development to have all the features of the python2 ones, and need some clearing up including trimming the included files and compressing more. Some recipes also will no yet work with python3, though most do.
除非您的脚本很复杂并且充分利用了py2/py3的主要区别(例如unicode处理),否则使用python2可能并不困难.由于它们几乎是同一语言,因此您可能不需要重写",只需进行一些小改动即可.
Unless your script is complicated and makes significant use of the major py2/py3 differences such as unicode handling, it probably wouldn't be difficult to use python2 instead. Since they're almost the same language, you probably don't need a 'rewrite', just a few small changes.
这篇关于在Android上使用Buildozer使用python3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!