在 Ubuntu 18 上构建 pyjnius 时 python-for-android 失败

Posted

技术标签:

【中文标题】在 Ubuntu 18 上构建 pyjnius 时 python-for-android 失败【英文标题】:python-for-android faild while building pyjnius on Ubuntu 18 【发布时间】:2019-05-23 08:10:53 【问题描述】:

我是 ubuntu 和 python-for-android 的新手,我第一次尝试使用 p4a 构建一个 apk,在我收到此错误之前一切似乎都运行良好:

sabeer@sabeer-pc:~$ p4a apk --private $HOME/code/myapp --package=org.example.myapp --name "My application" --version 0.1  --bootstrap=sdl2 --requirements=python2,kivy,pyjnius
[INFO]:    Will compile for the following archs: armeabi
[INFO]:    Found Android API target in $ANDROIDAPI
[INFO]:    Available Android APIs are (19)
[INFO]:    Requested API target 19 is available, continuing.
[INFO]:    Found NDK dir in $ANDROIDNDK
[INFO]:    Got NDK version from $ANDROIDNDKVER
[INFO]:    Using Google NDK r18b
[INFO]:    Found virtualenv at /home/sabeer/.local/bin/virtualenv
[INFO]:    Found the following toolchain versions: ['4.9']
[INFO]:    Picking the latest gcc toolchain, here 4.9
[WARNING]: Missing executable: pkg-config is not installed
[INFO]:    No existing dists meet the given requirements!
[INFO]:    No dist exists that meets your requirements, so one will be built.
[INFO]:    Found multiple valid dependency orders:
[INFO]:        ['hostpython2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', u'python2', 'sdl2', 'six', 'pyjnius', u'kivy']
[INFO]:        ['hostpython2', 'pygame_bootstrap_components', u'python2', 'sdl', 'six', 'pygame', 'pyjnius', u'kivy']
[INFO]:    Using the first of these: ['hostpython2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', u'python2', 'sdl2', 'six', 'pyjnius', u'kivy']
[INFO]:    The selected bootstrap is sdl2_gradle
[INFO]:    # Creating dist with sdl2_gradle bootstrap
[INFO]:    Dist will have name unnamed_dist_51 and recipes (python2, kivy, pyjnius)
[INFO]:    Dist will also contain modules () installed from pip
[INFO]:    -> running cp -r /home/sabeer/.local/lib/...(and 150 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/bootstrap_builds/sdl2_gradle-python2
[INFO]:    <- directory context /home/sabeer
[INFO]:    Recipe build order is ['hostpython2', 'sdl2_image', 'sdl2_mixer', 'sdl2_ttf', u'python2', 'sdl2', 'six', 'pyjnius', u'kivy']
[INFO]:    # Downloading recipes 
[INFO]:    Downloading hostpython2
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 43 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/hostpython2
[INFO]:    -> running basename https://python.org/ftp...(and 34 more)
[INFO]:    hostpython2 download already cached, skipping                       
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading sdl2_image
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 42 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/sdl2_image
[INFO]:    -> running basename https://www.libsdl.or...(and 52 more)
[INFO]:    sdl2_image download already cached, skipping                        
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading sdl2_mixer
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 42 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/sdl2_mixer
[INFO]:    -> running basename https://www.libsdl.or...(and 52 more)
[INFO]:    sdl2_mixer download already cached, skipping                        
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading sdl2_ttf
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 40 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/sdl2_ttf
[INFO]:    -> running basename https://www.libsdl.org...(and 48 more)
[INFO]:    sdl2_ttf download already cached, skipping                          
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading python2
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 39 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/python2
[INFO]:    -> running basename https://python.org/ftp...(and 34 more)
[INFO]:    python2 download already cached, skipping                           
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading sdl2
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 36 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/sdl2
[INFO]:    -> running basename https://www.libsdl.org...(and 26 more)
[INFO]:    sdl2 download already cached, skipping                              
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading six
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 35 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/six
[INFO]:    -> running basename https://pypi.python.or...(and 40 more)
[INFO]:    six download already cached, skipping                               
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading pyjnius
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 39 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/pyjnius
[INFO]:    -> running basename https://github.com/kiv...(and 28 more)
[INFO]:    pyjnius download already cached, skipping                           
[INFO]:    <- directory context /home/sabeer
[INFO]:    Downloading kivy
[INFO]:    -> running mkdir -p /home/sabeer/.local/sh...(and 36 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/packages/kivy
[INFO]:    -> running basename https://github.com/kiv...(and 25 more)
[INFO]:    kivy download already cached, skipping                              
[INFO]:    <- directory context /home/sabeer
[INFO]:    # Building all recipes for arch armeabi
[INFO]:    # Unpacking recipes
[INFO]:    Unpacking hostpython2 for armeabi
[INFO]:    -> running basename https://python.org/ftp...(and 34 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/other_builds/hostpython2/desktop
[INFO]:    hostpython2 is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking sdl2_image for armeabi
[INFO]:    -> running basename https://www.libsdl.or...(and 52 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/bootstrap_builds/sdl2_gradle-python2/jni
[INFO]:    sdl2_image is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking sdl2_mixer for armeabi
[INFO]:    -> running basename https://www.libsdl.or...(and 52 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/bootstrap_builds/sdl2_gradle-python2/jni
[INFO]:    sdl2_mixer is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking sdl2_ttf for armeabi
[INFO]:    -> running basename https://www.libsdl.org...(and 48 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/bootstrap_builds/sdl2_gradle-python2/jni
[INFO]:    sdl2_ttf is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking python2 for armeabi
[INFO]:    -> running basename https://python.org/ftp...(and 34 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/other_builds/python2/armeabi
[INFO]:    python2 is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking sdl2 for armeabi
[INFO]:    -> running basename https://www.libsdl.org...(and 26 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/bootstrap_builds/sdl2_gradle-python2/jni
[INFO]:    sdl2 is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking six for armeabi
[INFO]:    -> running basename https://pypi.python.or...(and 40 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/other_builds/six-python2/armeabi
[INFO]:    six is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking pyjnius for armeabi
[INFO]:    -> running basename https://github.com/kiv...(and 28 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/other_builds/pyjnius-python2-sdl2/armeabi
[INFO]:    pyjnius is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    Unpacking kivy for armeabi
[INFO]:    -> running basename https://github.com/kiv...(and 25 more)
[INFO]:    -> directory context /home/sabeer/.local/share/python-for-android/build/other_builds/kivy-python2-sdl2/armeabi
[INFO]:    kivy is already unpacked, skipping
[INFO]:    <- directory context /home/sabeer
[INFO]:    # Prebuilding recipes
[INFO]:    Prebuilding hostpython2 for armeabi
[INFO]:    -> running cp /home/sabeer/.local/lib/pyt...(and 173 more)
[INFO]:    Prebuilding sdl2_image for armeabi
[INFO]:    sdl2_image has no prebuild_armeabi, skipping
[INFO]:    Applying patches for sdl2_image[armeabi]
[INFO]:    sdl2_image already patched, skipping
[INFO]:    Prebuilding sdl2_mixer for armeabi
[INFO]:    sdl2_mixer has no prebuild_armeabi, skipping
[INFO]:    Applying patches for sdl2_mixer[armeabi]
[INFO]:    sdl2_mixer already patched, skipping
[INFO]:    Prebuilding sdl2_ttf for armeabi
[INFO]:    sdl2_ttf has no prebuild_armeabi, skipping
[INFO]:    Prebuilding python2 for armeabi
[INFO]:    python2 has no prebuild_armeabi, skipping
[INFO]:    Applying patches for python2[armeabi]
[INFO]:    python2 already patched, skipping
[INFO]:    Prebuilding sdl2 for armeabi
[INFO]:    sdl2 has no prebuild_armeabi, skipping
[INFO]:    Applying patches for sdl2[armeabi]
[INFO]:    sdl2 already patched, skipping
[INFO]:    Prebuilding six for armeabi
[INFO]:    six has no prebuild_armeabi, skipping
[INFO]:    Prebuilding pyjnius for armeabi
[INFO]:    pyjnius has no prebuild_armeabi, skipping
[INFO]:    Applying patches for pyjnius[armeabi]
[INFO]:    Applying patch sdl2_jnienv_getter.patch
[INFO]:    -> running patch -t -d /home/sabeer/.loca...(and 195 more)
           working: 1 out of 1 hunk FAILED -- saving rejects t...(and 19 more) Exception in thread background thread for pid 4591:
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/sabeer/.local/lib/python2.7/site-packages/sh.py", line 2170, in background_thread
    handle_exit_code(exit_code)
  File "/home/sabeer/.local/lib/python2.7/site-packages/sh.py", line 1929, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/sabeer/.local/lib/python2.7/site-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
ErrorReturnCode_1: 

  RAN: /usr/bin/patch -t -d /home/sabeer/.local/share/python-for-android/build/other_builds/pyjnius-python2-sdl2/armeabi/pyjnius -p1 -i /home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/recipes/pyjnius/sdl2_jnienv_getter.patch

  STDOUT:
patching file jnius/jnius_jvm_android.pxi
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file jnius/jnius_jvm_android.pxi.rej
patching file setup.py
Hunk #1 FAILED at 53.
1 out of 1 hunk FAILED -- saving rejects to file setup.py.rej


  STDERR:


[INFO]:    STDOUT:                                                             
    patching file jnius/jnius_jvm_android.pxi   
Hunk #1 FAILED at 1.    
1 out of 1 hunk FAILED -- saving rejects to file jnius/jnius_jvm_android.pxi.rej
patching file setup.py  
Hunk #1 FAILED at 53.   
1 out of 1 hunk FAILED -- saving rejects to file setup.py.rej
[INFO]:    STDERR:

Traceback (most recent call last):
  File "/home/sabeer/.local/bin/p4a", line 11, in <module>
    sys.exit(main())
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 975, in main
    ToolchainCL()
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 512, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 149, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/toolchain.py", line 193, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/build.py", line 566, in build_recipes
    recipe.apply_patches(arch)
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/recipe.py", line 486, in apply_patches
    arch.arch)
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/recipe.py", line 194, in apply_patch
    "-i", filename, _tail=10)
  File "/home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/logger.py", line 175, in shprint
    for line in output:
  File "/home/sabeer/.local/lib/python2.7/site-packages/sh.py", line 720, in next
    self.wait()
  File "/home/sabeer/.local/lib/python2.7/site-packages/sh.py", line 651, in wait
    self.handle_command_exit_code(exit_code)
  File "/home/sabeer/.local/lib/python2.7/site-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /usr/bin/patch -t -d /home/sabeer/.local/share/python-for-android/build/other_builds/pyjnius-python2-sdl2/armeabi/pyjnius -p1 -i /home/sabeer/.local/lib/python2.7/site-packages/pythonforandroid/recipes/pyjnius/sdl2_jnienv_getter.patch

  STDOUT:
patching file jnius/jnius_jvm_android.pxi
Hunk #1 FAILED at 1.
1 out of 1 hunk FAILED -- saving rejects to file jnius/jnius_jvm_android.pxi.rej
patching file setup.py
Hunk #1 FAILED at 53.
1 out of 1 hunk FAILED -- saving rejects to file setup.py.rej


  STDERR:

我在 Windows 10 旁边使用 Ubuntu 18,我尝试了可能的解决方案,但似乎没有一个对我有用。如果我能得到帮助来解决这个问题,我会很高兴。

【问题讨论】:

【参考方案1】:

在 Ubuntu 18.04 上,我的 buildozer 构建失败,出现 jnius/jnius.c: no file or folder error。

我的 python3 virtualenv cython 版本是 0.21(每个文档)。但是当我升级到最新版本的 cython (0.29.5) 时,Pyjnius 构建没有问题。

[注意:这没有改变,但我还在操作系统级别安装了最新的 cython:sudo pip install -U cythonsudo pip install cython==0.29.5]

pip install -U cythonpip install cython==0.29.5

稍后我们可能需要将 cython 版本重置为 0.21,但这似乎是一次性构建的,因此如果需要,我们可以将 cython 重置为 0.21 (pip install cython==0.21) 以获取其他 buildozer 依赖项,并且不会再看到此问题相同的构建虚拟机/机器。

【讨论】:

以上是关于在 Ubuntu 18 上构建 pyjnius 时 python-for-android 失败的主要内容,如果未能解决你的问题,请参考以下文章

在 Windows、Linux 等上运行 pyjnius

尝试在 Xampp (ubuntu 18.04) 上安装备份时无法登录到 wordpress 管理区域

如何执行 ./distribute.sh -m 'pyjnius kivy' 这个命令

我是不是必须在 Ubuntu 18.04 上从源代码构建 gcc-10 才能卸载 OpenMP GPU 目标?

在 Windows 上安装 pyjnius

在 android 上使用 pyjnius 连接到 wifi 网络