0

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 ?

TryinHard
  • 4,078
  • 3
  • 28
  • 54

1 Answers1

0

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.

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • I did everything in the first thread you sent and second one, it's still not working. –  Oct 02 '15 at 03:27
  • Not working - like what? What is your Android.mk doing? – Alex Cohn Oct 02 '15 at 04:50
  • When I try to compile I get this: [armeabi] Compile++ thumb: Face <= Face.cpp In file included from jni/Face.cpp:2:0: jni/opencv2/core/core.hpp:56:21: fatal error: algorithm: No such file or directory #include ^ compilation terminated. –  Oct 02 '15 at 05:02
  • For OpenCV 3.0 you need `NDK_TOOLCHAIN_VERSION=4.8 APP_STL=gnustl_static`. Are these defined in `Application.mk` or on **ndk-build** ocmmand line? – Alex Cohn Oct 02 '15 at 05:23
  • Actually I'm using OpenCV 2.4.11 for Android not the version 3.0 but both of those variables has been set already in my new Application.mk (since I didn't have one before) –  Oct 02 '15 at 06:08
  • have you checked that this `Application.mk` is loaded by **ndk-build**? – Alex Cohn Oct 02 '15 at 10:29