android - 使用 ubuntu 和 buildozer 为 android 打包应用程序时出错
问题描述
先决条件
我试图弄清楚如何使用buildozer打包 python 应用程序。在浪费了很多小时试图这样做之后,我已经到了一个我被卡住的地步,这里是我所遵循的步骤的一个小总结:
下载ubuntu16.04 x64 .vdi,解压并使用virtualbox运行。
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev git
sudo apt-get install build-essential ccache git libncurses5:i386 libstdc++6:i386 libgtk2.0-0:i386 libpangox-1.0-0:i386 libpangoxft-1.0-0:i386 libidn11:i386 python2.7 python2.7-dev openjdk-8-jdk unzip zlib1g-dev zlib1g:i386
sudo apt install curl git
curl -L https://raw.githubusercontent.com/yyuu/pyenv-installer/master/bin/pyenv-installer | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo -e 'if command -v pyenv 1>/dev/null 2>&1; then\n eval "$(pyenv init -)"\nfi' >> ~/.bashrc
pyenv install 3.6.2
pyenv global 3.6.2
pip install virtualenv
pip install --upgrade pip
- 创建具有写入权限的共享文件夹+automont 并重新启动
sudo usermod -aG vboxsf osboxes && reboot
cd /media/sf_android_apps/
pip install cython==0.21
pip install buildozer
此时......“理论上”一切都应该准备好烘焙 apk,所以让我们尝试构建一个最小的 hello world 应用程序:
APP + 规格
hello_world.py:
print('hello android!!!')
buildozer.spec:
默认内容但更改 log_level
...
log_level = 2
...
错误
1)当我尝试从 virtualbox 共享文件夹位置构建应用程序时,我会得到:
osboxes@osboxes:/media/sf_android_apps$ buildozer -v android debug
...
Traceback (most recent call last):
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1073, in <module>
main()
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1067, in main
ToolchainCL()
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 576, in __init__
getattr(self, args.subparser_name.replace('-', '_'))(args)
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 151, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 200, in build_dist_from_args
build_recipes(build_order, python_modules, ctx)
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 548, in build_recipes
recipe.prepare_build_dir(arch.arch)
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 505, in prepare_build_dir
self.unpack(arch)
File "/media/sf_android_apps/.buildozer/android/platform/python-for-android/pythonforandroid/recipe.py", line 404, in unpack
sh.tar('xf', extraction_filename)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 1427, in __call__
return RunningCommand(cmd, call_args, stdin, stdout, stderr)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 774, in __init__
self.wait()
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 792, in wait
self.handle_command_exit_code(exit_code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_2:
RAN: /bin/tar xf /media/sf_android_apps/.buildozer/android/platform/build/packages/sdl2_image/SDL2_image-2.0.4.tar.gz
STDOUT:
STDERR:
/bin/tar: SDL2_image-2.0.4/Xcode/Frameworks/webp.framework/Resources: Cannot create symlink to ‘Versions/Current/Resources’: Read-only file system
/bin/tar: SDL2_image-2.0.4/Xcode/Frameworks/webp.framework/webp: Cannot create symlink to ‘Versions/Current/webp’: Read-only file system
/bin/tar: SDL2_image-2.0.4/Xcode/Frameworks/webp.framework/Headers: Cannot create symlink to ‘Versions/Current/Headers’: Read-only file system
/bin/tar: SDL2_image-2.0.4/Xcode/Frameworks/webp.framework/Versions/Current: Cannot create symlink to ‘A’: Read-only file system
/bin/tar: Exiting with failure status due to previous errors
# Command failed: /home/osboxes/.pyenv/versions/3.6.2/bin/python3.6 -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/media/sf_android_apps/.buildozer/android/platform/build" --ndk-api=21
#
# 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
2)当我尝试从普通文件夹位置执行相同操作时,我会得到:
osboxes@osboxes:~/foo$ buildozer -v android debug
...
[INFO]: -> running autogen.sh
Exception in thread background thread for pid 16689:
Traceback (most recent call last):
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 1540, in wrap
fn(*args, **kwargs)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 2459, in background_thread
handle_exit_code(exit_code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 2157, in fn
return self.command.handle_command_exit_code(exit_code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_127:
RAN: /home/osboxes/foo/.buildozer/android/platform/build/build/other_builds/libffi/armeabi-v7a__ndk_target_21/libffi/autogen.sh
STDOUT:
/home/osboxes/foo/.buildozer/android/platform/build/build/other_builds/libffi/armeabi-v7a__ndk_target_21/libffi/autogen.sh: 2: exec: autoreconf: not found
STDERR:
Traceback (most recent call last):
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1073, in <module>
main()
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 1067, in main
ToolchainCL()
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 576, in __init__
getattr(self, args.subparser_name.replace('-', '_'))(args)
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 151, in wrapper_func
build_dist_from_args(ctx, dist, args)
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/toolchain.py", line 200, in build_dist_from_args
build_recipes(build_order, python_modules, ctx)
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/build.py", line 562, in build_recipes
recipe.build_arch(arch)
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/recipes/libffi/__init__.py", line 33, in build_arch
shprint(sh.Command('./autogen.sh'), _env=env)
File "/home/osboxes/foo/.buildozer/android/platform/python-for-android/pythonforandroid/logger.py", line 178, in shprint
for line in output:
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 863, in next
self.wait()
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 792, in wait
self.handle_command_exit_code(exit_code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/sh.py", line 815, in handle_command_exit_code
raise exc
sh.ErrorReturnCode_127:
RAN: /home/osboxes/foo/.buildozer/android/platform/build/build/other_builds/libffi/armeabi-v7a__ndk_target_21/libffi/autogen.sh
STDOUT:
/home/osboxes/foo/.buildozer/android/platform/build/build/other_builds/libffi/armeabi-v7a__ndk_target_21/libffi/autogen.sh: 2: exec: autoreconf: not found
STDERR:
# Command failed: /home/osboxes/.pyenv/versions/3.6.2/bin/python3.6 -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=kivy --arch armeabi-v7a --copy-libs --color=always --storage-dir="/home/osboxes/foo/.buildozer/android/platform/build" --ndk-api=21
#
# 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
问题
你知道如何在这里继续,这样我就可以使用 buildozer 成功地为 android 烘焙这个小小的 hello world 应用程序吗?
另一个不成功的尝试
尝试1:
我已经测试了@Ronald Saunfe 的答案,所以我已经降级到 0.32 但也没有运气
osboxes@osboxes:~/foo$ pwd
/home/osboxes/foo
osboxes@osboxes:~/foo$ buildozer android clean
osboxes@osboxes:~/foo$ pip install buildozer==0.32
这是我遇到的错误:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
PYTHON-FOR-ANDROID ERROR! SEE BELOW FOR SOLUTION:
You are trying to run an old version of python-for-android via
distribute.sh. However, python-for-android has been rewritten and no
longer supports the distribute.sh interface.
If you are using buildozer, you should:
- upgrade buildozer to the latest version (at least 0.30)
- delete the .buildozer folder in your app directory (the same directory that has your buildozer.spec)
- run buildozer again as normal
If you are not using buildozer, see
https://github.com/kivy/python-for-android/blob/master/README.md for
instructions on using the new python-for-android
toolchain. Alternatively, you can get the old toolchain from the
'old_toolchain' branch at
https://github.com/kivy/python-for-android/tree/old_toolchain .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# Command failed: ./distribute.sh -l
#
# 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
尝试2:
与尝试 1 相同,但在这种情况下,我已经从 /home/osboxes 和 /home/osboxes/foo 中删除了 .buildozer,这也会导致错误:
building 'jnius' extension
creating build
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/jnius
ccache arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/osboxes/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -DNDEBUG -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/osboxes/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -fPIC -I/home/osboxes/foo/.buildozer/android/platform/python-for-android/build/python-install/include/python2.7 -c jnius/jnius.c -o build/temp.linux-x86_64-2.7/jnius/jnius.o
arm-linux-androideabi-gcc: error: jnius/jnius.c: No such file or directory
arm-linux-androideabi-gcc: fatal error: no input files
compilation terminated.
error: command 'ccache' failed with exit status 1
Traceback (most recent call last):
File "/home/osboxes/.pyenv/versions/3.6.2/bin/cython", line 11, in <module>
load_entry_point('Cython==0.21', 'console_scripts', 'cython')()
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 632, in setuptools_main
return main(command_line = 1)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 649, in main
result = compile(sources, options)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 624, in compile
return compile_multiple(source, options)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 602, in compile_multiple
result = run_pipeline(source, options, context=context)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Main.py", line 439, in run_pipeline
err, enddata = Pipeline.run_pipeline(pipeline, source)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Pipeline.py", line 328, in run_pipeline
data = phase(data)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Pipeline.py", line 54, in generate_pyx_code_stage
module_node.process_implementation(options, result)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/ModuleNode.py", line 111, in process_implementation
self.generate_c_code(env, options, result)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/ModuleNode.py", line 328, in generate_c_code
self.body.generate_function_definitions(env, code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 398, in generate_function_definitions
stat.generate_function_definitions(env, code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 398, in generate_function_definitions
stat.generate_function_definitions(env, code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 1859, in generate_function_definitions
self.generate_function_body(env, code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 1628, in generate_function_body
self.body.generate_execution_code(code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 404, in generate_execution_code
stat.generate_execution_code(code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 6610, in generate_execution_code
fresh_finally_clause().generate_execution_code(code)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/site-packages/Cython/Compiler/Nodes.py", line 6598, in fresh_finally_clause
node_copy = copy.deepcopy(node)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 215, in _deepcopy_list
append(deepcopy(a, memo))
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 280, in _reconstruct
state = deepcopy(state, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 150, in deepcopy
y = copier(x, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 240, in _deepcopy_dict
y[deepcopy(key, memo)] = deepcopy(value, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 180, in deepcopy
y = _reconstruct(x, memo, *rv)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 297, in _reconstruct
item = deepcopy(item, memo)
File "/home/osboxes/.pyenv/versions/3.6.2/lib/python3.6/copy.py", line 169, in deepcopy
rv = reductor(4)
TypeError: can't pickle Argument objects
/home/osboxes/foo/.buildozer/android/platform/python-for-android/build/python-install/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
running build_ext
building 'jnius' extension
ccache arm-linux-androideabi-gcc -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/osboxes/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -DNDEBUG -DANDROID -mandroid -fomit-frame-pointer --sysroot /home/osboxes/.buildozer/android/platform/android-ndk-r9c/platforms/android-19/arch-arm -fPIC -I/home/osboxes/foo/.buildozer/android/platform/python-for-android/build/python-install/include/python2.7 -c jnius/jnius.c -o build/temp.linux-x86_64-2.7/jnius/jnius.o
arm-linux-androideabi-gcc: error: jnius/jnius.c: No such file or directory
arm-linux-androideabi-gcc: fatal error: no input files
compilation terminated.
error: command 'ccache' failed with exit status 1
# Command failed: ./distribute.sh -m "kivy" -d "myapp"
#
# 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
解决方案
我目前正在使用 Buildozer 但这可能对某些人来说是一种解决方法
buildozer android clean
sudo pip install buildozer==0.32
sudo pip install cython==0.21
buildozer android debug
推荐阅读
- python - 我如何编码我的鼠标点击?我设法通过使用用户输入来做 e.get() 但现在,我想做一个鼠标版本
- c++ - 如何在 C++ 控制台应用程序中设置整行背景颜色
- flutter - Flutter 如何在多个 web 路由之间制作一个通用的小部件?
- racket - 在球拍和定义窗口行为中导入单个函数
- webhooks - 如何保护托管在 Azure 应用服务上的自定义 Webhook 以捕获 Azure 监视器警报
- python - 为什么我的 for 循环只打印第一个结果?
- java - 从android中的xml文件更改自定义视图的文本颜色
- visual-studio-code - 如何更改vscode中的vim复制粘贴快捷方式
- r - 全局变量“密度”没有可见的绑定
- java - 如何使 Java HttpPost 在正文中不包含 url