ErrorWhenCompilingTo Android x86_64:找不到 zlib 的头文件或库文件,这是从源代码编译 Pillow 时必需的依赖项

分享于2022年07月17日 android buildozer python windows-subsystem-for-linux x86-64 问答
【问题标题】:ErrorWhenCompilingTo Android x86_64:找不到 zlib 的头文件或库文件,这是从源代码编译 Pillow 时必需的依赖项(ErrorWhenCompilingTo Android x86_64: The headers or library files could not be found for zlib, a required dependency when compiling Pillow from source)
【发布时间】:2022-01-26 23:42:05
【问题描述】:

我正在使用适用于 Linux 的 Windows 子系统 (WSL):

  • Python3 3.8.10
  • 来自 /home/paul/.local/lib/python3.8/site-packages/pip (python 3.8) 的 pip 21.3.1

使用 pip 安装 Pillow :

python3 -m pip install --upgrade Pillow

buildozer.spec (已编辑):

[app]

# (str) Title of your application
title = Screen_Recorder

# (str) Package name
package.name = screen_recorder

# (str) Package domain (needed for android/ios packaging)
package.domain = org.test

# (str) Source code where the main.py live
source.dir = .

# (list) Source files to include (let empty to include all the files)
source.include_exts = py,png,jpg,kv,atlas

# (str) Application versioning (method 1)
version = 0.1

# (list) Application requirements
# comma separated e.g. requirements = sqlite3,kivy
requirements = python3, kivy==2.0.0, android, numpy, pillow, opencv==4.5.3, plyer, vidgear, colorlog, chardet, requests, idna, urllib3, tqdm, mss, pyscreenshot, EasyProcess, entrypoint2, jeepney, streamlink, isodate, iso3166, iso-639, pycryptodome, PySocks, websocket-client, urllib3
# lxml, libxcb

# (str) Supported orientation (one of landscape, sensorLandscape, portrait or all)
orientation = all

#
# OSX Specific
#

#
# author = © Copyright Info

# change the major version of python used by the app
osx.python_version = 3

# Kivy version to use
osx.kivy_version = 2.0.0

#
# Android specific
#

# (bool) Indicate if the application should be fullscreen or not
fullscreen = 0

# (string) Presplash background color (for android toolchain)
# Supported formats are: #RRGGBB #AARRGGBB or one of the following names:
# red, blue, green, black, white, gray, cyan, magenta, yellow, lightgray,
# darkgray, grey, lightgrey, darkgrey, aqua, fuchsia, lime, maroon, navy,
# olive, purple, silver, teal.
android.presplash_color = #FFFFFF

# (list) Permissions
android.permissions = RECORD_AUDIO, WRITE_EXTERNAL_STORAGE, READ_EXTERNAL_STORAGE

# (str) Android logcat filters to use
android.logcat_filters = *:S python:D

# (str) The Android arch to build for, choices: armeabi-v7a , arm64-v8a (tested not work for my phone Samsung Galaxy J7 Prime), x86 (tested can't even install Samsung Galaxy J7 Prime), x86_64 (issue when building -zlib -lxml)
android.arch = x86_64


# (bool) enables Android auto backup feature (Android API >=23)
android.allow_backup = True


#
# iOS specific
#

# (str) Path to a custom kivy-ios folder
#ios.kivy_ios_dir = ../kivy-ios
# Alternately, specify the URL and branch of a git checkout:
ios.kivy_ios_url = https://github.com/kivy/kivy-ios
ios.kivy_ios_branch = master

# Another platform dependency: ios-deploy
# Uncomment to use a custom checkout
#ios.ios_deploy_dir = ../ios_deploy
# Or specify URL and branch
ios.ios_deploy_url = https://github.com/phonegap/ios-deploy
ios.ios_deploy_branch = 1.10.0

# (bool) Whether or not to sign the code
ios.codesign.allowed = false


[buildozer]

# (int) Log level (0 = error only, 1 = info, 2 = debug (with command output))
log_level = 2

# (int) Display warning if buildozer is run as root (0 = False, 1 = True)
warn_on_root = 1

我的项目所需的库:

  • 基维

  • numpy

  • opencv==4.5.3
  • 视频设备

  • plyer

编译到 Android x86_64 时,出现以下错误:

[INFO]:    Building Pillow for x86_64
[INFO]:    Pillow apparently isn't already in site-packages
[INFO]:    Building compiled components in Pillow
[INFO]:    -> directory context /mnt/c/Python/Python__GUI/Kivy/MyKivyScreenRecorderApp/Packages/Android/.buildozer/android/platform/build-x86_64/build/other_builds/Pillow/x86_64__ndk_target_21/Pillow
[INFO]:    -> running python3 setup.py build_ext -v                                                                                working:    https://pillow.readthedocs.io/en/latest/installation.html

Exception in thread background thread for pid 26935:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs) 
  File "/home/paul/.local/lib/python3.8/site-packages/sh.py", line 1683, in wrap
    fn(*rgs, **kwargs)
  File "/home/paul/.local/lib/python3.8/site-packages/sh.py", line 2662, in background_thread
    handle_exit_code(exit_code)
  File "/home/paul/.local/lib/python3.8/site-packages/sh.py", line 2349, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/home/paul/.local/lib/python3.8/site-packages/sh.py", line 905, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1:

  RAN: /mnt/c/Python/Python__GUI/Kivy/MyKivyScreenRecorderApp/Packages/Android/.buildozer/android/platform/build-x86_64/build/other_builds/hostpython3/desktop/hostpython3/native-build/python3 setup.py build_ext -v

  STDOUT:
running build_ext

The headers or library files could not be found for zlib,
a required dependency when compiling Pillow from source.

Please see the install instructions at:
https://pillow.readthedocs.io/en/latest/installation.html

//其他错误类似


【解决方案1】:

只是想在编译到 Android x86_64 时给其他人建议一个解决方案作为参考 (编译成功,但不知道是否有效)(欢迎任何其他建议/答案:))

  • 第一次构建失败后
  • 在您的项目目录中
  • 转到 ./.buildozer/android/platform/python-for-android/pythonforandroid/recipes/ 以更改所需配方的 NDK xlib 路径
  • 在例如 ./Pillow/ ./Python3/
  • 找到类似的东西:
ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib')
zlib_lib_path = join(self.ctx.ndk_platform, 'usr', 'lib')
  • 并评论或替换为
ndk_lib_dir = join(self.ctx.ndk_platform, 'usr', 'lib64')
zlib_lib_path = join(self.ctx.ndk_platform, 'usr', 'lib64')
  • 保存并尝试重新构建项目

参考。 :

问题: Android x86_64 instant crash with hello world app, missing zlib

文档。 : grep

stackexchange 问题: How to search strings inside files like in Windows without search monkey?

stackoverflow 问题: How to grep and replace