Reputation:
I'm quite new using Android Studio 1.3.2 and even more using the NDK. I'm trying to using OpenCV 2.4.11 and C++. I'm using Gradle 2.6.
So far and oddly OpenCV doesn't generate any errors in the C++ code. Just When I'm including C++ headers like or , it cannot resolve them. Same goes for Try...Catch that are unresolved. Again, I started using Android Studio like 2 weeks ago and NDK 1 week ago. I'm still not sure what I'm doing.
#include "jni.h"
#include <vector>
#include <string>
#include <opencv2/contrib/contrib.hpp>
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jlong JNICALL Java_face_rt_facert_FisherFaceRecognizer_createFisherFaceRecognizer_10(JNIEnv *env,
jclass type) {
try {
cv::Ptr<cv::FaceRecognizer> pfr = cv::createFisherFaceRecognizer();
pfr.addref(); // this is for the 2.4 branch, 3.0 would need a different treatment here
return (jlong) pfr.obj;
} catch (...) {
jclass je = env->FindClass("java/lang/Exception");
env->ThrowNew(je, "sorry, dave..");
}
return 0;
}
#ifdef __cplusplus
}
#endif
My build.gradle file for the project:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "face.rt.facert"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 19
versionCode = 1
versionName = "1.0.1"
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.txt')
}
}
android.ndk { // keeping it to make AS correctly support C++ code editing and debugging
moduleName = "Face"
ldLibs += ['log']
cppFlags += "-std=c++11"
cppFlags += "-fexceptions"
cppFlags += "-I${file("src/main/jni/prebuilts/include")}".toString()
cppFlags += "-I${file("C:/Android-dev/SDKs/OpenCV-android-sdk/sdk/native/jni/include")}".toString()
cppFlags += "-I${file("C:/Android-dev/SDKs/OpenCV-android-sdk/sdk/native/jni/include/opencv")}".toString()
cppFlags += "-I${file("C:/Android-dev/SDKs/OpenCV-android-sdk/sdk/native/jni/include/opencv2")}".toString()
stl = "gnustl_shared" //"stlport_static"
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" @
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.with {
abiFilters += "armeabi"
File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi\\" //"-L" +
ldLibs += libsDir + "libnative_camera_r4.3.0.so"
ldLibs += libsDir + "libopencv_contrib.a"
ldLibs += libsDir + "libopencv_core.a"
ldLibs += libsDir + "libopencv_highgui.a"
ldLibs += libsDir + "libopencv_imgproc.a"
ldLibs += libsDir + "libopencv_info.so"
ldLibs += libsDir + "libopencv_java.so"
ldLibs += libsDir + "libopencv_legacy.a"
ldLibs += libsDir + "libopencv_ml.a"
ldLibs += libsDir + "libopencv_ts.a"
}
}
create("armv7") {
ndk.with {
abiFilters += "armeabi-v7a"
File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\armeabi-v7a\\" //"-L" +
ldLibs += libsDir + "libnative_camera_r4.3.0.so"
ldLibs += libsDir + "libopencv_contrib.a"
ldLibs += libsDir + "libopencv_core.a"
ldLibs += libsDir + "libopencv_highgui.a"
ldLibs += libsDir + "libopencv_imgproc.a"
ldLibs += libsDir + "libopencv_info.so"
ldLibs += libsDir + "libopencv_java.so"
ldLibs += libsDir + "libopencv_legacy.a"
ldLibs += libsDir + "libopencv_ml.a"
ldLibs += libsDir + "libopencv_ts.a"
}
}
create("x86") {
ndk.with {
abiFilters += "x86"
}
}
create("mips") {
ndk.with {
abiFilters += "mips"
}
}
create("fat") {
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':openCVLibrary2411')
}
And this is my dependencies in my project:
classpath 'com.android.tools.build:gradle-experimental:0.3.0-alpha3'
EDIT:
Removed Try...Catch from the function for testing purpose. Oddly, vector and string headers are now resolved and working.
But now I'm getting few errors about OpenCV at the compile time.
Error:(16) undefined reference to `cv::createFisherFaceRecognizer(int, double)'
Error:(2607) undefined reference to `cv::fastFree(void*)'
Error:Execution failed for task ':app:linkArm64-v8aDebugAllFaceSharedLibrary'. A build operation failed. Linker failed while linking libFace.so.
Upvotes: 0
Views: 1875
Reputation:
I found in my build.gradle:
// To include all cpu architectures, leaves abiFilters empty
create("all")
all means 32 and 64 bits. Since my libs are only 32 bits, compiler didn't find the 64bits version and failed.
I removed this line and it works better (Still have some errors but not compiling errors)
Upvotes: 1