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 (已编辑):


# (str) Title of your application
title = Screen_Recorder

# (str) Package name = screen_recorder

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

# (str) Source code where the 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

# (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 =
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 =
ios.ios_deploy_branch = 1.10.0

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


# (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 build_ext -v                                                                                working:

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

  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 build_ext -v

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:



只是想在编译到 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