我使用Android Studio 1.3.2和Gradle 2.6使用NDK进行实验。
这是我的错误:
dlopen("/data/app/face.rt.jeanc.facert-2/lib/arm/libFace.so", RTLD_LAZY) failed: dlopen failed: "/data/app/face.rt.jeanc.facert-2/lib/arm/libFace.so" has unexpected e_machine: 40
另外,我的lib Face应该在我的文件夹(armabi,armabi-v7等)中显示为libFace.so但是没有出现(编译?)
这是我的build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.1"
defaultConfig.with {
applicationId = "face.rt.jeanc.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()
ldLibs += ["android", "EGL", "GLESv2", "dl", "log", "z"]// , "ibopencv_core"
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"
File curDir = file('./')
curDir = file(curDir.absolutePath)
String libsDir = curDir.absolutePath+"\\src\\main\\jniLibs\\x86\\" //"-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("mips") {
ndk.with {
abiFilters += "mips"
}
}
create("fat") {
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:23.0.1'
compile project(':openCVLibrary2411')
}
这是我的代码的一部分"应该"加载不同的库:
////// JNI C++
static {System.loadLibrary("Face");}
//Externals C++ Libraries
static {System.loadLibrary("libnative_camera_r4.3.0.so");}
static {System.loadLibrary("libopencv_contrib.a");}
static {System.loadLibrary("libopencv_core.a");}
static {System.loadLibrary("libopencv_highgui.a");}
static {System.loadLibrary("libopencv_imgproc.a");}
static {System.loadLibrary("libopencv_info.so");}
static {System.loadLibrary("libopencv_java.so");}
static {System.loadLibrary("libopencv_legacy.a");}
static {System.loadLibrary("libopencv_ml.a");}
static {System.loadLibrary("libopencv_ts.a");}
我现在有点困难,需要一些帮助。
编辑:在这个版本的Android工作室和实验性插件中,我没有Android.Mk文件来编译jni c ++。所以我想知道现在它是自己做的还是我必须手动编译?如果我手动没有安装Android.Mk,请手动如何操作?
答案 0 :(得分:0)
您的构建成功,但您不能将共享库从OpenCV复制到应用程序的libs目录。遵循How to use opencv in android studio using gradle build tool?
中的建议请注意,可以将Android.mk的全部功能与 experimental 插件结合使用:请参阅define LOCAL_SRC_FILES in ndk{} DSL。