使用ubuntu和buildozer为Android打包错误的应用程序

时间:2019-02-10 22:38:39

标签: android python ubuntu virtualbox buildozer

必备条件

我正在尝试找出如何使用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 + SPEC

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应用程序?

另一个未成功的尝试

Attempt1:

我已经测试了@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

Attempt2:

与try1相同,但是在这种情况下,我从/ 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

1 个答案:

答案 0 :(得分:0)

我目前正在使用Buildozer,但这可能可以解决某些问题

buildozer android clean
sudo pip install buildozer==0.32
sudo pip install cython==0.21
buildozer android debug