opencv - java.lang.ExceptionInInitializerError in Android Project -
i'm trying create android application can record video and, during recording, should capture frames in order process them. when try run app on emulator (using eclipse juno, opencv4android ver. 2.4.5, , android-ndk), have result in logcat:
05-13 18:15:34.555: d/dalvikvm(1595): trying 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): not load library "libopencv_java.so" needed "libjnivideocapture.so"; caused 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 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): @ java.lang.class.newinstanceimpl(native method) 05-13 18:15:34.575: e/androidruntime(1595): @ java.lang.class.newinstance(class.java:1319) 05-13 18:15:34.575: e/androidruntime(1595): @ android.app.instrumentation.newactivity(instrumentation.java:1054) 05-13 18:15:34.575: e/androidruntime(1595): @ android.app.activitythread.performlaunchactivity(activitythread.java:2097) 05-13 18:15:34.575: e/androidruntime(1595): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 05-13 18:15:34.575: e/androidruntime(1595): @ android.app.activitythread.access$600(activitythread.java:141) 05-13 18:15:34.575: e/androidruntime(1595): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 05-13 18:15:34.575: e/androidruntime(1595): @ android.os.handler.dispatchmessage(handler.java:99) 05-13 18:15:34.575: e/androidruntime(1595): @ android.os.looper.loop(looper.java:137) 05-13 18:15:34.575: e/androidruntime(1595): @ android.app.activitythread.main(activitythread.java:5041) 05-13 18:15:34.575: e/androidruntime(1595): @ java.lang.reflect.method.invokenative(native method) 05-13 18:15:34.575: e/androidruntime(1595): @ java.lang.reflect.method.invoke(method.java:511) 05-13 18:15:34.575: e/androidruntime(1595): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 05-13 18:15:34.575: e/androidruntime(1595): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 05-13 18:15:34.575: e/androidruntime(1595): @ 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): not load library "libopencv_java.so" needed "libjnivideocapture.so"; caused load_library(linker.cpp:745): library "libopencv_java.so" not found 05-13 18:15:34.575: e/androidruntime(1595): @ java.lang.runtime.loadlibrary(runtime.java:371) 05-13 18:15:34.575: e/androidruntime(1595): @ java.lang.system.loadlibrary(system.java:535) 05-13 18:15:34.575: e/androidruntime(1595): @ com.example.provavideocapture.mainactivity.<clinit>(mainactivity.java:21) 05-13 18:15:34.575: e/androidruntime(1595): ... 15 more
it 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 default camera if (!cap.isopened()) //check if 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 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 copy manually in dir libs of project library libopencv_java.so, taking opencv tutorial project, , i've loaded jnivideocapture in mainactivity, without better results, because when run project, library automatically removed libs/.
how can fix problem?
just add line:
opencv_lib_type:=static
right after:
include $(clear_vars)
you didn't link (statically) opencv library project - mistake.
Comments
Post a Comment