Python binding prolem when cross compiling OpenCV4.10 with Android cmake and NDK toolchains on Ubuntu

  1. Environment and Target

Build environment: Ubuntu
Target environment: aarch64-Linux-Android
I have cross compiled Python 3.11 and it can run on Android arm-v8a. I want to cross compile OpenCV to generate a Python library that supports the target environment.

  1. Building and Question
    This is my cmake script:
export PYTHON3=/home/ad/dev-lib/python311
export PKG_CONFIG_PATH=/home/ad/dev-lib/python311/lib/pkgconfig:$PKG_CONFIG_PATH

/home/ad/Android/Sdk/cmake/4.0.2/bin/cmake \
 -DCMAKE_TOOLCHAIN_FILE=/home/ad/Android/Sdk/ndk/27.2.12479018/build/cmake/android.toolchain.cmake \
 -DCMAKE_BUILD_TYPE=Release \
 -DANDROID_ABI:STRING=arm64-v8a \
 -DANDROID_PLATFORM:STRING=android-30 \
 -DCMAKE_INSTALL_PREFIX:PATH=/home/ad/dev-lib/Opecv-4.10.0/myinstall \
 -DBUILD_opencv_python3:BOOL=ON \
 -DBUILD_SHARED_LIBS:BOOL=ON \
 -DPYTHON3_EXECUTABLE:FILEPATH=${PYTHON3}/bin/python3.11 \
 -DPYTHON3_INCLUDE_DIR:PATH=${PYTHON3}/include/python3.11 \
 -DPYTHON3_LIBRARY:FILEPATH=${PYTHON3}/lib/libpython3.so \
 -DPYTHON3_PACKAGES_PATH:STRING=${PYTHON3}/lib/python3.11/site-packages \
 -DPYTHON3_NUMPY_INCLUDE_DIRS:PATH=/home/ad/dev-lib/numpy/dist2/lib/python3.11/site-packages/numpy/_core/include \
 -DOpenBLAS_INCLUDE_DIR:PATH=/home/ad/dev-lib/OpenBLAS1/myinstall/include \
 -DOpenBLAS_LIB:FILEPATH=/home/ad/dev-lib/OpenBLAS1/myinstall/lib/libopenblas.so \
 -DPYTHON3_CVPY_SUFFIX=".so" \
 -DOpenCV_BINARY_DIR:STATIC=/home/ad/opencv-4.10.0/mybuild \
 -DBUILD_LIST=core,imgproc \
 -DBUILD_opencv_apps=OFF \
 -DBUILD_EXAMPLES=OFF \
 -DBUILD_TESTS=OFF \
 -DBUILD_PERF_TESTS=OFF \
 -DBUILD_DOCS=OFF \
 -DBUILD_PACKAGE=OFF \
 -DBUILD_opencv_dnn=OFF \
 -S ./ -B ./mybuild

But after executing the cmake command, the options related to Python 3 are empty, as shown in the following figure.

Configuration process of cmake section

ad@ad-virtual-machine:~/dev-lib/opencv-4.10.0$ ./cmake-opencv.sh
CMake Deprecation Warning at CMakeLists.txt:25 (cmake_minimum_required):
Compatibility with CMake < 3.10 will be removed from a future version of
CMake.

Update the VERSION argument value. Or, use the … syntax
to tell CMake that the project requires at least but has been updated
to work with policies introduced by or earlier.

– General configuration for OpenCV 4.10.0 =====================================
– Version control: unknown

– Platform:
– Timestamp: 2025-07-19T11:38:32Z
– Host: Linux 6.8.0-60-generic x86_64
– Target: Android 1 aarch64
– CMake: 4.0.2
– CMake generator: Unix Makefiles
– CMake build tool: /usr/bin/gmake
– Configuration: Release

– CPU/HW features:
– Baseline: NEON FP16
– Dispatched code generation: NEON_DOTPROD NEON_FP16 NEON_BF16
– requested: NEON_FP16 NEON_BF16 NEON_DOTPROD
– NEON_DOTPROD (1 files): + NEON_DOTPROD
– NEON_FP16 (0 files): + NEON_FP16
– NEON_BF16 (0 files): + NEON_BF16

– C/C++:
– Built as dynamic libs?: YES
– C++ standard: 11
– C++ Compiler: /home/ad/Android/Sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ (ver 18.0.3)
– C++ flags (Release): -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
– C++ flags (Debug): -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -fno-limit-debug-info -O0 -DDEBUG -D_DEBUG
– C Compiler: /home/ad/Android/Sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
– C flags (Release): -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG -DNDEBUG
– C flags (Debug): -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winconsistent-missing-override -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -Wno-deprecated-enum-enum-conversion -Wno-deprecated-anon-enum-enum-conversion -fdiagnostics-show-option -Qunused-arguments -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -fno-limit-debug-info -O0 -DDEBUG -D_DEBUG
– Linker flags (Release): -static-libstdc++ -Wl,–build-id=sha1 -Wl,–no-undefined-version -Wl,–fatal-warnings -Wl,–no-undefined -Qunused-arguments -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined -Wl,–gc-sections
– Linker flags (Debug): -static-libstdc++ -Wl,–build-id=sha1 -Wl,–no-undefined-version -Wl,–fatal-warnings -Wl,–no-undefined -Qunused-arguments -Wl,–gc-sections -Wl,–as-needed -Wl,–no-undefined
– ccache: NO
– Precompiled headers: NO
– Extra dependencies: dl m log
– 3rdparty dependencies:

– OpenCV modules:
– To be built: core imgproc
– Disabled: dnn world
– Disabled by dependency: calib3d features2d flann gapi highgui imgcodecs java_bindings_generator js_bindings_generator ml objc_bindings_generator objdetect photo stitching video videoio
– Unavailable: java python2 python3 ts
– Applications: -
– Documentation: NO
– Non-free algorithms: NO

– Android NDK: /home/ad/Android/Sdk/ndk/27.2.12479018 (ver 27.2.12479018)
– Android ABI: arm64-v8a
– NDK toolchain: aarch64-linux-android-clang
– STL type: c++_static
– Native API level: 30
– Android SDK: /home/ad/Android/Sdk (tools: build tools: 36.0.0)

– GUI:

– Media I/O:
– ZLib: z (ver 1.3.0.1)
– JPEG: build-libjpeg-turbo (ver 3.0.3-70)
– SIMD Support Request: YES
– SIMD Support: YES
– WEBP: build (ver encoder: 0x020f)
– PNG: build (ver 1.6.43)
– SIMD Support Request: YES
– SIMD Support: YES (Arm NEON)
– TIFF: build (ver 42 - 4.6.0)
– JPEG 2000: build (ver 2.5.0)
– OpenEXR: build (ver 2.3.0)
– HDR: YES
– SUNRASTER: YES
– PXM: YES
– PFM: YES

– Video I/O:
– MEDIANDK: YES
– NDK Camera: YES

– Parallel framework: pthreads

– Trace: YES (with Intel ITT)

– Other third-party libraries:
– Custom HAL: YES (carotene (ver 0.0.1, Auto detected))
– Protobuf: build (3.19.1)
– Flatbuffers: builtin/3rdparty (23.5.9)

– Python 3:
– Interpreter: NO
– Libraries: NO
– Limited API: NO
– numpy: /home/ad/dev-lib/numpy/dist2/lib/python3.11/site-packages/numpy/_core/include (ver )
– install path: -

– Python (for build): NO

– Java:
– ant: NO
– Java wrappers: NO
– Java tests: NO

– Install to: /home/ad/dev-lib/Opecv-4.10.0/myinstall



– Configuring done (29.1s)
– Generating done (0.5s)
– Build files have been written to: /home/ad/dev-lib/opencv-4.10.0/mybuild