Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Build OpenCV 4.x for Android with c++_static

I had been happily using opencv as a shared library, but now I want to try out this open source project where they link to it statically. The only problem is google stopped supporting gnustl and gcc. Now they want clang and c++_static. So I've been trying to build 4.x and 3.x (failing miserably on 3.x because it wants an old version of the sdk tools and ndk).

But for 4.x I'm close, it's compiling but it's not generating the android_sdk directory or the jni files. I'm just using cmake and ninja like this. Am I missing a command switch to build the sdk portion?

cmake -GNinja -DINSTALL_ANDROID_EXAMPLES=ON -DANDROID_EXAMPLES_WITH_LIBS=ON -DBUILD_EXAMPLES=ON -DBUILD_DOCS=OFF -DWITH_OPENCL=OFF -DWITH_IPP=ON -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN=clang "-DANDROID_STL=c++_static" "-DANDROID_ABI=arm64-v8a" -DANDROID_SDK_TARGET=18 "-DANT_EXECUTABLE=D:/apache-ant-1.10.6-bin/apache-ant-1.10.6/bin/ant.bat" ./opencv-4.1.1/opencv-4.1.1

And here's the end of the output where most things look happy.

-- ccache: NO -- Precompiled headers: NO -- Extra dependencies: dl m log

-- 3rdparty dependencies:

-- OpenCV modules: -- To be built: calib3d core dnn features2d flann highgui im gcodecs imgproc java ml objdetect photo stitching ts video videoio -- Disabled: world -- Disabled by dependency: - -- Unavailable: gapi js python2 python3 -- Applications: tests perf_tests examples -- Documentation: NO

-- Non-free algorithms: NO

-- Android NDK: C:/Users/blank/AppData/Local/And roid/sdk/ndk-bundle (ver 19.2.5345600) -- Android ABI: arm64-v8a -- NDK toolchain: aarch64-linux-android-clang -- STL type: c++_static -- Native API level: 21 -- Android SDK: C:/Users/blank/AppData/Local/And

roid/sdk (tools: 26.1.1 build tools: 29.0.2)

-- GUI:

-- Media I/O: -- ZLib: C:/Users/blank/AppData/Local/And roid/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/i686 -linux-android/libz.a (ver 1.2.7) -- JPEG: build-libjpeg-turbo (ver 2.0.2-62) -- WEBP: build (ver encoder: 0x020e) -- PNG: build (ver 1.6.37) -- TIFF: build (ver 42 - 4.0.10) -- JPEG 2000: build (ver 1.900.1) -- OpenEXR: build (ver 2.3.0) -- HDR: YES -- SUNRASTER: YES -- PXM: YES

-- PFM: YES

-- Video I/O:

-- Parallel framework: pthreads

-- Trace: YES (with Intel ITT)

-- Other third-party libraries: -- Custom HAL: NO

-- Protobuf: build (3.5.1)

-- Python (for build): [redacted]/python.exe

-- Java: -- ant: D:/apache-ant-1.10.6-bin/apache-ant-1.10.6/b in/ant.bat (ver ) -- Java wrappers: YES

-- Java tests: NO

-- Install to: D:/opencv_builds/install

-- -----------------------------------------------------------------

-- Configuring done -- Generating done -- Build files have been written to: D:/opencv_builds

D:\opencv_builds>

Build OpenCV 4.x for Android with c++_static

I had been happily using opencv as a shared library, but now I want to try out this open source project where they link to it statically. The only problem is google stopped supporting gnustl and gcc. Now they want clang and c++_static. So I've been trying to build 4.x and 3.x (failing miserably on 3.x because it wants an old version of the sdk tools and ndk).

But for 4.x I'm close, it's compiling but it's not generating the android_sdk directory or the jni files. I'm just using cmake and ninja like this. Am I missing a command switch to build the sdk portion?

cmake -GNinja -DINSTALL_ANDROID_EXAMPLES=ON -DANDROID_EXAMPLES_WITH_LIBS=ON -DBUILD_EXAMPLES=ON -DBUILD_DOCS=OFF -DWITH_OPENCL=OFF -DWITH_IPP=ON -DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%/build/cmake/android.toolchain.cmake -DANDROID_TOOLCHAIN=clang "-DANDROID_STL=c++_static" "-DANDROID_ABI=arm64-v8a" -DANDROID_SDK_TARGET=18 "-DANT_EXECUTABLE=D:/apache-ant-1.10.6-bin/apache-ant-1.10.6/bin/ant.bat" ./opencv-4.1.1/opencv-4.1.1

And here's the end of the output where most things look happy.

-- ccache: NO
-- Precompiled headers: NO
-- Extra dependencies: dl m log

log -- 3rdparty dependencies:

dependencies: -- -- OpenCV modules: -- To be built: calib3d core dnn features2d flann highgui im gcodecs imgproc java ml objdetect photo stitching ts video videoio -- Disabled: world -- Disabled by dependency: - -- Unavailable: gapi js python2 python3 -- Applications: tests perf_tests examples -- Documentation: NO

NO -- Non-free algorithms: NO

NO -- -- Android NDK: C:/Users/blank/AppData/Local/And roid/sdk/ndk-bundle (ver 19.2.5345600) -- Android ABI: arm64-v8a -- NDK toolchain: aarch64-linux-android-clang -- STL type: c++_static -- Native API level: 21 -- Android SDK: C:/Users/blank/AppData/Local/And

C:/Users/blank/AppData/Local/And roid/sdk (tools: 26.1.1 build tools: 29.0.2)

-- GUI:

29.0.2) -- -- GUI: -- -- Media I/O: -- ZLib: C:/Users/blank/AppData/Local/And roid/sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/lib/i686 -linux-android/libz.a (ver 1.2.7) -- JPEG: build-libjpeg-turbo (ver 2.0.2-62) -- WEBP: build (ver encoder: 0x020e) -- PNG: build (ver 1.6.37) -- TIFF: build (ver 42 - 4.0.10) -- JPEG 2000: build (ver 1.900.1) -- OpenEXR: build (ver 2.3.0) -- HDR: YES -- SUNRASTER: YES -- PXM: YES

YES -- PFM: YES

YES -- -- Video I/O:

I/O: -- -- Parallel framework: pthreads

pthreads -- -- Trace: YES (with Intel ITT)

ITT) -- -- Other third-party libraries: -- Custom HAL: NO

NO -- Protobuf: build (3.5.1)

(3.5.1) -- -- Python (for build): [redacted]/python.exe

[redacted]/python.exe -- -- Java: -- ant: D:/apache-ant-1.10.6-bin/apache-ant-1.10.6/b in/ant.bat (ver ) -- Java wrappers: YES

YES -- Java tests: NO

NO -- -- Install to: D:/opencv_builds/install

-- -----------------------------------------------------------------

D:/opencv_builds/install -- ----------------------------------------------------------------- -- -- Configuring done -- Generating done -- Build files have been written to: D:/opencv_builds

D:/opencv_builds

D:\opencv_builds>

D:\opencv_builds>