1

While using OpenCV library I am getting the error:

Error:Execution failed for task ':app:compileDebugNdk'.  Error: Your project contains C++ files but it is not using a supported native build system.   Consider using CMake or ndk-build integration with the stable Android Gradle plugin:    https://developer.android.com/studio/projects/add-native-code.html   or use the experimental plugin:    http://tools.android.com/tech-docs/new-build-system/gradle-experimental.`

When i created the jniLibs folder then it shows me the cpp folder and not when i run the app it shows that i have cpp files but they are not using a supprted native build system

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79

2 Answers2

1

I was able to build opencv from git (https://github.com/opencv/opencv/tree/3.1.0) using the NDK's cmake yesterday.

export ANDROID_NDK=~/android-sdks/ndk-bundle
cmake -GNinja -DANDROID_TOOLCHAIN_NAME=clang -DANDROID_ABI=armeabi-v7a \
    -DANDROID_ARM_NEON=ON -DENABLE_NEON=ON -DANDROID_STL=c++_static \
    -DANDROID_CPP_FEATURES="rtti exceptions" -DANDROID_PLATFORM=android-9 \
    -DBUILD_ANDROID_EXAMPLES=OFF -DBUILD_DOCS=OFF -DBUILD_FAT_JAVA_LIB=OFF \
    -DBUILD_JASPER=OFF -DBUILD_OPENEXR=OFF -DBUILD_PACKAGE=OFF \
    -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_TIFF=ON \
    -DBUILD_WITH_DEBUG_INFO=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_java=OFF \
    -DBUILD_opencv_python2=OFF -DBUILD_opencv_world=OFF \
    -DCMAKE_C_FLAGS_RELEASE="-Os -DNDEBUG -fvisibility=hidden -ffunction-sections -fstack-protector-all" \
    -DCMAKE_CXX_FLAGS_RELEASE="-Os -DNDEBUG -fvisibility=hidden -ffunction-sections -fstack-protector-all -fvisibility-inlines-hidden" \
    -DENABLE_PRECOMPILED_HEADERS=OFF -DWITH_EIGEN=OFF -DWITH_JASPER=OFF \
    -DWITH_OPENEXR=OFF -DWITH_TIFF=ON -DWITH_TBB=ON -DWITH_CUDA=OFF \
    -DWITH_CUFFT=OFF -DWITH_WEBP=OFF -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
    path/to/opencv

That's command line use, but something similar should work if you're building from within Android Studio. I'm guessing you don't need all those options, but those were the instructions given to me.

Unfortunately there's a bug in the NDK r13 cmake toolchain that needed to be fixed first: https://github.com/android-ndk/ndk/issues/234. We're about to publish the first beta for NDK r14 which does have the fix. You shouldn't use the betas for production, but if you're not planning to ship right away it should reach stable release in February.

Dan Albert
  • 10,079
  • 2
  • 36
  • 79
  • I tried to run this with NDK r14 on openCV 3.1. but i got 'Run Build Command:"/usr/local/bin/ninja" "cmTC_1103f" [1/2] Building CXX object CMakeFiles/cmTC_1103f.dir/testCXXCompiler.cxx.o [2/2] Linking CXX executable cmTC_1103f FAILED: cmTC_1103f error: cannot find -lc++_static' Do you have an idea what could cause this? – Someone Apr 26 '17 at 14:59
  • Unless you've deviated from those commands, no. I just reran it with r14b and it's still working fine. – Dan Albert Apr 26 '17 at 18:42
  • Thank you for your answer. I was able to build it, my issue was probably due to serveral versions of the ndk with some weird exports. Once i cleared my bash_profile it worked fine. – Someone Apr 27 '17 at 06:45
0

Try download latest OpenCV SDK from here and add it to your project by steps, described by @ssimm here

Community
  • 1
  • 1
Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79