简体   繁体   中英

Android Studio opencv C++ compile link libraries error at runtime

I'm using Android Studio 1.3.2 with Gradle 2.6 experimental with NDK.

This is my error:

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

Also, my lib Face should appears as libFace.so in my folders (armabi, armabi-v7, etc) but doesn't appear (compile ?)

Here is my 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')
}

This is part of my code that "should" load the different libraries:

////// 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");}

I'm kinda stuck for now and need some help.

EDIT: In this version of Android studio and the experimental plugin I don't have Android.Mk file to compile jni c++. So I was wondering if now it does it by itself or I have to compile manually ?

If manually how do I do that since I don't have Android.Mk ?

Your build does succeed, but you don't copy the shared libs from OpenCV to libs directory of your app. Follow the advice in How to use opencv in android studio using gradle build tool?

Note that it is possible to combine full power of Android.mk with the experimental plugin: see define LOCAL_SRC_FILES in ndk{} DSL .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM