Skip to content

Instantly share code, notes, and snippets.

@rsp9u
Last active April 5, 2021 04:04
Show Gist options
  • Select an option

  • Save rsp9u/d34819f7e348b455cf38cc474a5e876c to your computer and use it in GitHub Desktop.

Select an option

Save rsp9u/d34819f7e348b455cf38cc474a5e876c to your computer and use it in GitHub Desktop.
cmake build with OpenCV 3,4,13 & Android NDK r17c
cmake_minimum_required(VERSION 3.4.1)
project(hello-jni)
set(OpenCV_DIR "/path/to/OpenCV-android-sdk/sdk/native/jni/abi-armeabi-v7a")
find_package(OpenCV REQUIRED)
set(CMAKE_CXX_FLAGS "-O2 -std=c++11 -Wno-format-security --include-directory-after /path/to/android-ndk-r17c/sysroot/usr/include/arm-linux-androideabi")
add_library(hello-jni SHARED hello-jni.cpp)
target_include_directories(hello-jni PUBLIC ${OpenCV_INCLUDE_DIRS})
target_link_libraries(hello-jni android log)
target_link_libraries(hello-jni ${OpenCV_LIBS})

setup

# curl -Lo ndk.zip https://dl.google.com/android/repository/android-ndk-r17c-linux-x86_64.zip
# unzip -q ndk.zip && rm -f ndk.zip
# curl -Lo opencv.zip https://github.com/opencv/opencv/releases/download/3.4.13/opencv-3.4.13-android-sdk.zip
# unzip -q opencv.zip && rm -f opencv.zip

build

# cd /path/to/project
# mkdir -p build
# cd build
# cmake \
>  -D CMAKE_TOOLCHAIN_FILE=/path/to/android-ndk-r17c/build/cmake/android.toolchain.cmake \
>  -D ANDROID_ABI=armeabi-v7a \
>  -D ANDROID_NATIVE_API_LEVEL=24 \
>  -D ANDROID_STL=gnustl_static \
>  ..
# make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment