我只是通过执行ndk-build
来开发使用C ++代码的Android应用程序。我一直使用OpenCV,所以在我的 Android.mk 中有:
include $(CLEAR_VARS)
OPENCV_LIB_TYPE:=SHARED
OPENCV_CAMERA_MODULES:=off
OPENCV_INSTALL_MODULES:=on
include /Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/jni/OpenCV.mk
include $(OPENCV_PATH)
并且它一直很好用。
现在我想用Android Studio调试C ++代码,我不得不在gradle中做一些修改。
首先,gradle没有看到包含文件,but I read this question in StackOverflow,它教我如何包含文件。现在,当我尝试构建我的应用程序时,出现以下错误:
错误:(60)未定义引用' cv :: _ InputArray :: _ InputArray(cv :: Mat const&)'
错误:(60)未定义引用' cv :: _ OutputArray :: _ OutputArray(cv :: Mat&)'
错误:(60)未定义引用' cv :: cvtColor(cv :: _ InputArray const&,cv :: _ OutputArray const&,int,int)'
错误:(62)未定义引用' cv :: _ InputArray :: _ InputArray(cv :: Mat const&)'
错误:(62)未定义引用' cv :: _ OutputArray :: _ OutputArray(cv :: Mat&)'
错误:(62)未定义引用' cv :: resize(cv :: _ InputArray const&,cv :: OutputArray const&,cv :: Size ,double,double, INT)'
错误:(73)未定义引用' cv :: Mat :: t()const'
错误:(73)未定义引用' cv :: _ InputArray :: _ InputArray(cv :: MatExpr const&)'
错误:(73)未定义引用' cv :: _ OutputArray :: _ OutputArray(cv :: Mat&)'
这让我怀疑找不到这些库。
我尝试将其添加到我的cFlags
中:
productFlavors {
x86 {
flavorDimension "abi"
ndk {
abiFilter "x86"
stl "stlport_shared"
cFlags "-std=c99 " +
"-fexceptions " +
"-I/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/jni/include " +
"-L/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/libs/x86 " +
"-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab"
}
}
arm {
flavorDimension "abi"
ndk {
abiFilter "armeabi-v7a"
stl "stlport_shared"
cFlags "-std=c99 " +
"-fexceptions " +
"-I/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/jni/include " +
"-L/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/libs/armeabi-v7a " +
"-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab"
}
}
}
我也试过这个:
buildTypes {
debug {
debuggable true
jniDebuggable = true
ndk {
abiFilter "x86"
stl "stlport_shared"
cFlags "-std=c99 " +
"-fexceptions " +
"-I/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/jni/include " +
"-L/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/libs/x86 " +
"-L/Users/rafaelruizmunoz/Desktop/Android_Tools/OpenCV-2.4.9-android-sdk/sdk/native/libs/armeabi-v7a " +
"-lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_ocl -lopencv_photo -lopencv_stitching -lopencv_superres -lopencv_ts -lopencv_video -lopencv_videostab"
}
release {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
但错误仍然存在。它无法找到图书馆。
我该怎么做?
提前谢谢。
答案 0 :(得分:0)
您需要 ldLibs 和 ldFlags 来指定链接库。使用 exeprimental 插件,我使用以下片段:
def appAbi = "armeabi-v7a"
def OpenCV_sdk = "~/opencv/sdk"
…
model { android.ndk {
…
ldFlags += "-L$OpenCV_sdk/native/libs/$appAbi".toString()
ldFlags += "-L$OpenCV_sdk/native/3rdparty/libs/$appAbi".toString()
ldLibs += ['opencv_imgproc', 'opencv_core', 'opencv_hal', 'tbb']
} }