There are many questions and answers surrounding getting native opencv for android building properly. Some use gradle, others use external tools. These numerous, complicate
With OpenCV 3.2 configuration could be actually quite short:
set(OpenCV_STATIC ON)
set(OpenCV_DIR ${OPENCV_HOME}/sdk/native/jni)
find_package (OpenCV REQUIRED)
target_link_libraries(native-lib ${OpenCV_LIBS})
That is it, 4 lines and no need to copy anything into your project. Just be sure that OPENCV_HOME points to the directory where OpenCV Android SDK is located.
One additional benefit of this approach - you can link with OpenCV statically, which would dramatically reduce the size of your app/library.
I use this approach in one of Github projects: https://github.com/Fotoapparat/FaceDetector
It seems you already have imported the opencv module, now, open your CMakeList.txt and add the follow lines:
set(CMAKE_VERBOSE_MAKEFILE on)
add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION
path-to-your-project/MyApplication/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
include_directories(path-to-opencv-directory/OpenCV-android-sdk/sdk/native/jni/include)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
and edit the:
target_link_libraries( # Specifies the target library.
native-lib
lib_opencv
# Links the target library to the log library
# included in the NDK.
$\{log-lib} )
to include your lib_opencv that you have created. To finish, you add the follow line:
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
in your module app, like this:
externalNativeBuild {
cmake {
cppFlags "-std=c++11 -frtti -fexceptions"
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
}
}
and below of buildTypes you add:
sourceSets {
main {
jniLibs.srcDirs = ['path to your application /MyApplication/app/src/main/jniLibs/']
}
}
For more details, you can see this: https://github.com/googlesamples/android-ndk/tree/master/cmake/hello-libs
Do same as Bruno Alexandre Krinski's Answer but
in place of this line
abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
put this line, (I don't know why this worked for me)
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
(Follow all the instructions of above answer except this)
ABIs [armeabi] are not supported for Android platform
Supported ABIs are [arm64-v8a, armeabi-v7a, x86, x86_64].
externalNativeBuild {
cmake {
// cppFlags ""
cppFlags "-std=c++11 -frtti -fexceptions"
// abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a', 'mips', 'mips64'
abiFilters 'x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a'
}
}