使用 buildozer 和 kivy 在 python 中制作 android 应用程序

Making android application in python using buildozer and kivy

我正在尝试使用 buildozer 构建 apk。但是当我 运行 buildozer -v android debug 命令构建 apk 时,我得到了以下错误

[INFO]:    Building python2 for armeabi-v7a
[INFO]:    Copying hostpython binary to targetpython folder
[INFO]:    -> running cp /home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/build/build/other_builds/hostpython2/deskto...(and 148 more)  
[INFO]:    Building sdl2 for armeabi-v7a
[INFO]:    -> directory context /home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/build/build/bootstrap_builds/sdl2-python2/jni
[INFO]:    -> running ndk-build V=1
Exception in thread background thread for pid 5175:
Traceback (most recent call last):
 File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
 self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/home/kallz/.local/lib/python2.7/site-packages/sh.py", line 2170, in background_thread
handle_exit_code(exit_code)
File "/home/kallz/.local/lib/python2.7/site-packages/sh.py", line 1929, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/kallz/.local/lib/python2.7/site-packages/sh.py", line 672, in handle_command_exit_code
raise exc
ErrorReturnCode_255: 

RAN: /home/kallz/.buildozer/android/platform/android-ndk-r9c/ndk-build V=1

STDOUT:


STDERR:


Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 916, in <module>
main()
File "/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 913, in main
ToolchainCL()
File "/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 514, in __init__
getattr(self, args.subparser_name.replace('-', '_'))(args)
File "/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 147, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/python-for-android-master/pythonforandroid/toolchain.py", line 192, in build_dist_from_args
build_recipes(build_order, python_modules, ctx)
File "pythonforandroid/build.py", line 572, in build_recipes
File "/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/python-for-android-master/pythonforandroid/recipes/sdl2/__init__.py", line 30, in build_arch
shprint(sh.ndk_build, "V=1", _env=env)
File "pythonforandroid/logger.py", line 175, in shprint
File "/home/kallz/.local/lib/python2.7/site-packages/sh.py", line 720, in next
self.wait()
File "/home/kallz/.local/lib/python2.7/site-packages/sh.py", line 651, in wait
self.handle_command_exit_code(exit_code)
File "/home/kallz/.local/lib/python2.7/site-packages/sh.py", line 672, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_255: 

RAN: /home/kallz/.buildozer/android/platform/android-ndk-r9c/ndk-build V=1

STDOUT:


STDERR:

# Command failed: /usr/bin/python2.7 -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=kivy,pyjnius,hostpython2,python2,plyer --arch armeabi-v7a --copy-libs --color=always --storage-dir=/home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/build

# Buildozer failed to execute the last command
# The error might be hidden in the log above this error
# Please read the full log, and search for it before
# raising an issue with buildozer itself.
# In case of a bug report, please add a full log with log_level = 2

我正在使用 python 2.7 ubuntu 17 我已经尝试过

我不知道缺少什么。 提前致谢

自己寻找解决方案

错误:

错误是在为 armeabi-v7a 构建 sdl2 时,因为您当前版本的 sdk ndk 或 .buildozer 中的 ndk 下载不完整或其他一些错误

Building sdl2 for armeabi-v7a
[INFO]:    -> directory context /home/kallz/Project/AndroidLib/examples/FaceD/.buildozer/android/platform/build/build/bootstrap_builds/sdl2-python2/jni
[INFO]:    -> running ndk-build V=1
Exception in thread background thread for pid 5175:
Traceback (most recent call last):

解法:

  1. 删除 .buildozer 主目录中的目录 Linux(其中安装了 android SDK ndk 或 ant)
  2. 从您的项目或应用中删除 .buildozer 目录
  3. 删除buildozer.spec文件

现在重新开始,运行在项目目录下执行命令

  1. buildozer 初始化
  2. buildozer -v android debug # 制作唯一的 apk

最后一条命令在主目录的 .buildozer 中再次自动下载 sdk ndk 或 ant