2

I'm trying to create an Android Application that can record a video and, during recording, it should capture frames in order to process them. But when I try to run my app on my emulator (using Eclipse Juno, OpenCV4Android ver. 2.4.5, and android-ndk), I have this result in my logcat:

05-13 18:15:34.555: D/dalvikvm(1595): Trying to load lib /data/app-lib/com.example.provavideocapture-1/libjniVideoCapture.so 0x40ce89b0
05-13 18:15:34.555: E/dalvikvm(1595): dlopen("/data/app-lib/com.example.provavideocapture-1/libjniVideoCapture.so") failed: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libopencv_java.so" needed by "libjniVideoCapture.so"; caused by load_library(linker.cpp:745): library "libopencv_java.so" not found
05-13 18:15:34.555: W/dalvikvm(1595): Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/example/provavideocapture/MainActivity;
05-13 18:15:34.555: W/dalvikvm(1595): Class init failed in newInstance call (Lcom/example/provavideocapture/MainActivity;)
05-13 18:15:34.555: D/AndroidRuntime(1595): Shutting down VM
05-13 18:15:34.555: W/dalvikvm(1595): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
05-13 18:15:34.575: E/AndroidRuntime(1595): FATAL EXCEPTION: main
05-13 18:15:34.575: E/AndroidRuntime(1595): java.lang.ExceptionInInitializerError
05-13 18:15:34.575: E/AndroidRuntime(1595):     at java.lang.Class.newInstanceImpl(Native Method)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at java.lang.Class.newInstance(Class.java:1319)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.os.Looper.loop(Looper.java:137)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at android.app.ActivityThread.main(ActivityThread.java:5041)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at java.lang.reflect.Method.invokeNative(Native Method)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at java.lang.reflect.Method.invoke(Method.java:511)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at dalvik.system.NativeStart.main(Native Method)
05-13 18:15:34.575: E/AndroidRuntime(1595): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libopencv_java.so" needed by "libjniVideoCapture.so"; caused by load_library(linker.cpp:745): library "libopencv_java.so" not found
05-13 18:15:34.575: E/AndroidRuntime(1595):     at java.lang.Runtime.loadLibrary(Runtime.java:371)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at java.lang.System.loadLibrary(System.java:535)
05-13 18:15:34.575: E/AndroidRuntime(1595):     at com.example.provavideocapture.MainActivity.<clinit>(MainActivity.java:21)
05-13 18:15:34.575: E/AndroidRuntime(1595):     ... 15 more

It is my code:

1) MainActivity.java

package com.example.provavideocapture;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView myTextField = (TextView)findViewById(R.id.myTextField);
    myTextField.setText(stringFromJNICPP()); 
}

public native String stringFromJNICPP();

static{
    System.loadLibrary("jniVideoCapture");
}

}

2) jniVideoCapture.cpp

#include <jni.h>
#include <string.h>
#include <android/log.h>
#include <opencv2/opencv.hpp>

extern "C" {
JNIEXPORT jstring JNICALL Java_com_example_provavideocapture_MainActivity_stringFromJNICPP(JNIEnv * env, jobject obj);
};

    JNIEXPORT jstring JNICALL Java_com_example_provavideocapture_MainActivity_stringFromJNICPP(JNIEnv * env, jobject obj){

/*VideoCapture cap(0); //open the default camera
if (!cap.isOpened()) //check if we succedeed
    return -1;

Mat edges;
namedWindow("edges",1);
for(;;){
    Mat frame;
    cap>>frame;
    cvtColor(frame,edges,CV_BGR2GRAY);
    GaussianBlur(edges,edges,Size(7,7),1.5,1.5);
    Canny(edges,edges,0,30,3);
    imshow("edges",edges);
    if(waitKey(30)>=0) break;
}*/
return env->NewStringUTF("Hello From CPP");

}

3) Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

include ../../Desktop/Android/OpenCV-2.4.5-android-sdk/sdk/native/jni/OpenCV.mk

LOCAL_MODULE    := jniVideoCapture
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_LDLIBS     += -llog -ldl
LOCAL_SRC_FILES := jniVideoCapture.cpp


include $(BUILD_SHARED_LIBRARY)

I've tried to copy manually in the dir libs of the project the library libopencv_java.so, taking it from an opencv tutorial project, and I've loaded it with the jniVideoCapture in the MainActivity, but without better results, because when I run the project, the library is automatically removed from libs/.

How can I fix this problem?

1
  • Please, Check my answer. It should help. Commented May 15, 2013 at 18:32

1 Answer 1

1

Just add line:

OPENCV_LIB_TYPE:=STATIC

right after:

include $(CLEAR_VARS)

You just didn't link (statically) opencv library to your project - this is a mistake.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.