在buildozer上使用android上的python3

mag*_*cus 5 android python-3.x kivy buildozer

我在python 3和kivy中编写了一个小程序.现在我想使用buildozer构建一个.apk并在我的Android手机上测试应用程序.一切正常,我能够在手机上安装应用程序,但应用程序在启动时崩溃.

错误日志显示,apk的python环境是python 2.7而不是3.我的问题是:是否有可能在android上使用python 3环境构建带有buildozer的apk?或者我是否必须在python2中重写应用程序?是否有可能破解迫使buildozer使用python3?

编辑:我按照inclement建议的步骤,并得到以下错误:

 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
Run Code Online (Sandbox Code Playgroud)

编辑2:这似乎是一个永无止境的故事.安装python3.5后遇到了这个错误:

collect2: error: ld returned 1 exit status
error: command 'arm-linux-androideabi-gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

随着我过去从错误发展到错误的时间,将代码更改为python2.7会更加明智,但现在我投入了大量时间,我只想最终实现它.:-)

那么有人知道如何解决这个问题吗?

最后编辑:我最终投降并更改了我的代码以使用python 2.7.我在此过程中监督的一个好建议:如果您使用期货,则必须将其添加到buildozer文件的要求中.否则,应用程序崩溃时会出现"空模块"错误消息.

现在,我的应用程序在手机上工作,我终于高兴:-)感谢恶意尝试帮助我解决我的问题.

inc*_*ent 3

我不确定 buildozer 是否有 python3 的构建选项,但 python-for-android 实验性地支持它。您可以通过从 master 分支安装 buildozer 并使用目标android_new( buildozer android_new debug) 来使用新版本的 python-for-android。如果 buildozer 将使用其 python3 选项,则需要添加python3crystax要求(如果存在,则替换 python2),手动下载 CrystaX NDK,并将 buildozer 的 NDK 路径选项设置为指向它。可能还需要写下kivy==1.9.1需求而不仅仅是写下kivy

Python3 版本仍在开发中,以具有 python2 版本的所有功能,并且需要一些清理工作,包括修剪包含的文件和压缩更多内容。有些食谱还不适用于 python3,但大多数都可以。

编辑:除非您的脚本很复杂并且充分利用了 py2/py3 的主要差异(例如 unicode 处理),否则使用 python2 可能并不困难。由于它们几乎是相同的语言,因此您可能不需要“重写”,只需进行一些小的更改即可。