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

oldcoder-pixel
Sat, 19 Jul 2025 12:00:06 +0000
Android/Java

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.

2. 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 (click for more details)
1 post - 1 participant