1

The errors:

Process: com.example.syafiq.opencvoi, PID: 7760
java.lang.UnsatisfiedLinkError: Couldn't load native_sample from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.syafiq.opencvoi-13.apk,libraryPath=/data/app-lib/com.example.syafiq.opencvoi-13]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at com.example.syafiq.opencvoi.Sample3Native$1.onManagerConnected(Sample3Native.java:79)
at org.opencv.android.AsyncServiceHelper$3.onServiceConnected(AsyncServiceHelper.java:319)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1114)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1131)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5602)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)

The sample3Native.java line 79 were:

 public void onManagerConnected(int status) {
        switch (status) {
            case LoaderCallbackInterface.SUCCESS:
            {
                Log.i(TAG, "OpenCV loaded successfully");

                // Load native library after(!) OpenCV initialization
                System.loadLibrary("native_sample");

And the AsyncServiceHelper.Java line 319 were

mUserAppCallback.onManagerConnected(status);

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include ../../sdk/native/jni/OpenCV.mk
LOCAL_MODULE    := native_sample
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl
include $(BUILD_SHARED_LIBRARY)

And application.mk

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi armeabi-v7a
LOCAL_ARM_NEON := true

There's no errors in the codes. I've tried several solution but yet the result are still the same, The codes was obtained from open source website. I'm not good enough with android studio, and I'm still learning. I hope you guys can help me to solve this error. I really appreciate your help and consideration to help me and solve my error. I appreciate your time :)

Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192

2 Answers2

0

From my perspective something wrong with versions of your "native_sample" library. As it's written in documentation

Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.

It's possible that there are both versions in your classpath, and jvm loads wrong version. So it finds library but during class-loading process find inconsistency, probably required method was added in later lib version.

I suggest trying this:

System.load(String path) //with an absolute path to needed lib

Also see: Difference between System.load() and System.loadLibrary in Java

Community
  • 1
  • 1
Rudziankoŭ
  • 10,681
  • 20
  • 92
  • 192
0
apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.syafiq.opencvoi"
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {

           // jniLibs.srcDirs = ['libs']
       main{
         jniLibs{
           srcDir 'libs'
         }
       }

    }


}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile project(':libraries:opencv')
}
tiny sunlight
  • 6,231
  • 3
  • 21
  • 42
  • It gave me an error :/ "No such property: srcDirs for class: com.android.build.gradle.internal.api.DefaultAndroidSourceSet_Decorated" – Syafiq Rosli Dec 13 '15 at 16:30
  • hey sorry for the late reply and thanks for editing it. It gave me different error "Gradle DSL method not found: srcDir(): possible cause: The project 'OpenCVoi' maybe using a version of Gradle that does not contain the method. and another cause was: The build file may be missing a Gradle Plugin" :/ – Syafiq Rosli Dec 14 '15 at 05:57
  • Can you push your project to github. Or can you provide the link you find the code?It's hard to slove just by single file. – tiny sunlight Dec 14 '15 at 14:42
  • here you go tiny sunlight, sorry for the late reply https://github.com/Ajay191191/Opencv-Face-Recognition – Syafiq Rosli Dec 15 '15 at 05:11