Search code examples
android-studiojava-native-interfacecentos7

How to Setup JNI Include Path for Android Studio


I am incoperating a JNI fuction in my Android Project however it can not resolve the header which is located at /usr/local/include/opencv2.How to direct Android Studio to look for header file over there?

It's Android studio 3 under CentOS 7.

Build command failed.
Error while executing process /home/<username>/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/<username>/AndroidStudioProjects/<project_name>/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target removebackground}
[1/2] Building CXX object CMakeFiles/removebackground.dir/src/main/cpp/removebackground.cpp.o
FAILED: /home/<username>/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=armv7-none-linux-androideabi --gcc-toolchain=/home/<username>/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/<username>/Android/Sdk/ndk-bundle/sysroot  -Dremovebackground_EXPORTS -I/home/<username>/opencv-android-sdk/sdk/native/jni/include -isystem /home/<username>/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include -isystem /home/<username>/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/include -isystem /home/<username>/Android/Sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/include/backward -isystem /home/<username>/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=16 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fno-integrated-as -mthumb -Wa,--noexecstack -Wformat -Werror=format-security  -frtti -fexceptions -O0 -fno-limit-debug-info  -fPIC -MD -MT CMakeFiles/removebackground.dir/src/main/cpp/removebackground.cpp.o -MF CMakeFiles/removebackground.dir/src/main/cpp/removebackground.cpp.o.d -o CMakeFiles/removebackground.dir/src/main/cpp/removebackground.cpp.o -c /home/<username>/AndroidStudioProjects/<project_name>/app/src/main/cpp/removebackground.cpp
/home/<username>/AndroidStudioProjects/<project_name>/app/src/main/cpp/removebackground.cpp:4:10: fatal error: 'opencv2/imgcodecs.hpp' file not found
#include <opencv2/imgcodecs.hpp>
         ^~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
ninja: build stopped: subcommand failed.

Solution

  • In the /app/CMakeLists.txt add

    include_directories(/usr/local/include)
    

    and that's all you gota do。

    Y(^_^)Y find solution to my own question all the time.