cmake error while building OpenCV in native on Android Studio

2.6k views Asked by At

I am trying to compile OpenCV in native on Android Studio. I am trying to follow : https://sriraghu.com/2017/03/11/opencv-in-android-an-introduction-part-1/ I was succesfully able to do it by following these steps on Windows. However on Ubuntu, its not working. The error is :

Execution failed for task ‘:app:externalNativeBuildDebug’. Build command failed. Error while executing process /home/user/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {–build /home/user/AndroidStudioProjects/project_folders/app/.externalNativeBuild/cmake/debug/arm64-v8a –target native-lib}

ninja: error: ‘../../../../jniLibs/src/main/jniLibs/arm64-v8a/libopencv_java3.so’, needed by ‘../../../../build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so’, missing and no known rule to make it

The CMakeLists.txt file is:

cmake_minimum_required(VERSION 3.4.1)
set(pathToOpenCV /media/user/Stuff/Softwares/OpenCV-android-sdk/sdk/native)
include_directories(${pathToOpenCV}/jni/include)

add_library( # Sets the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

add_library(lib_opencv SHARED IMPORTED)
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATIONS /home/user/cmu/android-apps/OpenCV_app_June23/OpenCV_Android/app/src/main/jniLibs/arm64-v8a/libopencv_java3.so)

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
                       native-lib

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} lib_opencv)

In native-lib.cpp, I am able to add #include without any error prompts in Android Studio. My previous searches suggest that there is something wrong with the paths. I have checked that the paths are correct, or is there a different way to put the path in Ubuntu?

0

There are 0 answers