Reputation: 448
I reinstalled Android Studio and it upgrade NDK and CMake to the lastest ones. After that I got this error:
Error while executing process /home/wxh/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/wxh/AndroidStudioProjects/Measure_It/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target removebackground}
[1/2] Building CXX object CMakeFiles/removebackground.dir/src/main/cpp/removebackground.cpp.o
[2/2] Linking CXX shared library
error: undefined reference to 'cv::imwrite(cv::String const&, cv::_InputArray const&, std::__ndk1::vector<int, std::__ndk1::allocator<int> > const&)'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
The code compiles fine before so there is no typo in that. To double check:
imgproc.hpp
was included.CMakeList.txt
has include path and library path:
include_directories(/home/wxh/Android/opencv_sdk/native/jni/include)
add_library( lib_opencv SHARED IMPORTED )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION /home/wxh/Android/opencv_sdk/native/libs/${ANDROID_ABI}/libopencv_java3.so)
app build.gradle
has
DefaultConfig{externalNativeBuild {
cmake { cppFlags "-frtti -fexceptions -std=c++11 "
arguments '-DANDROID_STL=c++_shared'
abiFilters 'armeabi-v7a'}}}
externalNativeBuild { cmake { path "CMakeLists.txt"} }
It has nothing to do with opencv becuase it hasn't been altered.
What else could be wrong???
Upvotes: 1
Views: 1061
Reputation: 57183
OpenCV 3 was using gunstl which is no longer supported in NDK. The new releases of NDK have only c++_static
and c++_shared
STL. You can rebuild OpenCV 3.x from sources with a new release of NDK and choose one of supported STL options, or you can use OpenCV 4.x which comes prebuilt with c++_static
.
It may be easier to fix your code to cover the API differences between 3.x and 4.x than to rebuild OpenCV from sources.
Upvotes: 1