Skip to content

Instantly share code, notes, and snippets.

@ogero
Last active January 12, 2022 05:33
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ogero/c19458cf64bd3e91faae85c3ac887481 to your computer and use it in GitHub Desktop.
Save ogero/c19458cf64bd3e91faae85c3ac887481 to your computer and use it in GitHub Desktop.
This process explains how to compile shared libs of opencv and contrib modules from sources for Android ABI `abi-armeabi-v7a`

Compilation of OpenCV & contrib modules from sources for Android

This process explains how to compile shared libs of opencv and contrib modules from sources for Android ABI abi-armeabi-v7a.

##Requirements

  • Sources for opencv-3.4.1
  • Sources for opencv_contrib-3.4.1
  • CMake 3.11.3
  • mingw-w64 x86_64-7.3.0-posix-seh-rt_v5-rev0
  • Android ndk

CMake

  • Extract opencv-3.4.1 inside opencv/opencv-3.4.1
  • Extract opencv_contrib-3.4.1 inside opencv/opencv_contrib-3.4.1
  • In CMake (cmake-gui) input Where is the source folder: opencv/opencv-3.4.1
  • In CMake (cmake-gui) input Where to build the binaries: opencv/build_android_arm
CMake Configuration options for android arm abi (search or add if missing)
  • Remove line 1090 (android_get_compatible_target(android_sdk_target_status ${ANDROID_NATIVE_API_LEVEL} ${ANDROID_SDK_TARGET} 11) from opencv/opencv-3.4.1CMakeLists.txt (see opencv/opencv#10929)
  • Add ANDROID_NDK = android/sdk/ndk-bundle
  • Add ANDROID_NATIVE_API_LEVEL = 16
  • Add ANDROID_NDK_HOST_X64 = 1
  • Configure
  • With MinGW Makefiles generator.
  • Specify toolchain file for cross-compiling: android/sdk/ndk-bundle/build/cmake/android.toolchain.cmake.
  • Wait for configuration..
  • Change ANDROID_EXECUTABLE = android/sdk/tools/android.bat
  • Change OPENCV_EXTRA_MODULES_PATH = opencv/opencv_contrib-3.4.1/modules
  • Change BUILD_ANDROID_EXAMPLES = 0
  • Change BUILD_DOCS = 0
  • Change BUILD_TESTS = 0
  • Change BUILD_PERF_TESTS = 0
  • Change ENABLE_PRECOMPILED_HEADERS = 0
  • Change ENABLE_CXX11 = 1
  • Change BUILD_SHARED_LIBS = 1
  • Change WITH_CAROTENE = 0
  • Change BUILD_ZLIB = 1
  • Change BUILD_JAVA = 0
  • Configure
  • Generate
Compile and install
  • Open a command line at opencv/build_android_arm
  • Run mingw32-make and wait for compile process.
  • Run mingw32-make install
  • Shared libs should be at opencv/build_android_arm/install/sdk/native/libs/armeabi-v7a
  • Header files should be at opencv/build_android_arm/install/sdk/native/jni/include
@william1994
Copy link

Thanks

@ogero
Copy link
Author

ogero commented Jun 16, 2018

Actually @william1994 this is a work in progress, as this configuration leads to undefined references when linking with gomobile.
hybridgroup/gocv#235

@deadprogram
Copy link

It appears that this is working now, according to @ogero

@dpanic
Copy link

dpanic commented Sep 3, 2021

Is there anything like this for 4.X?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment