如何设置JNI包含Android Studio的路径

时间:2018-03-30 09:19:26

标签: android-studio java-native-interface centos7

我在我的Android项目中运行JNI功能,但它无法解析位于/usr/local/include/opencv2的标题。如何指示Android Studio在那里查找头文件?

它是CentOS 7下的Android工作室3。

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.

1 个答案:

答案 0 :(得分:1)

在/app/CMakeLists.txt中添加

include_directories(/usr/local/include)

那就是你所做的一切。

Y (^_^) Y一直找到我自己的问题的解决方案。