简体   繁体   中英

Android Jni .so files ExceptionInInitializerError and UnsatisfiedLinkError: Library jniopencv_core not found

I am working an Android project which is based on Javacv .I have follwed the instructions which has been given in the project Readme.txt files . Placed all the .so files in libs/armeabi folder. and have used the following lines to convert the images to movie . But got following log.

* Logcat *

07-16 16:38:32.790: D/dalvikvm(27175): No JNI_OnLoad found in /data/data/com.javacv.ffmpeg/lib/libavutil.so 0x44e8db60, skipping init
07-16 16:38:32.800: W/dalvikvm(27175): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/googlecode/javacv/cpp/avutil;.<clinit>
07-16 16:38:32.800: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/avcodec;.<clinit>
07-16 16:38:32.800: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/avformat;.<clinit>
07-16 16:38:33.160: D/dalvikvm(27175): Trying to load lib /data/data/com.javacv.ffmpeg/lib/libopencv_core.so 0x44e8db60
07-16 16:38:33.160: I/dalvikvm(27175): Unable to dlopen(/data/data/com.javacv.ffmpeg/lib/libopencv_core.so): Cannot load library: get_lib_extents[759]:  1196 - /data/data/com.javacv.ffmpeg/lib/libopencv_core.so is not a valid ELF object
07-16 16:38:33.170: W/dalvikvm(27175): Exception Ljava/lang/UnsatisfiedLinkError; thrown during Lcom/googlecode/javacv/cpp/opencv_core;.<clinit>
07-16 16:38:33.170: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/opencv_imgproc;.<clinit>
07-16 16:38:33.170: W/dalvikvm(27175): Exception Ljava/lang/ExceptionInInitializerError; thrown during Lcom/googlecode/javacv/cpp/opencv_highgui;.<clinit>
07-16 16:38:33.170: D/AndroidRuntime(27175): Shutting down VM
07-16 16:38:33.170: W/dalvikvm(27175): threadid=1: thread exiting with uncaught exception (group=0x400207c8)
07-16 16:38:33.190: E/AndroidRuntime(27175): FATAL EXCEPTION: main
07-16 16:38:33.190: E/AndroidRuntime(27175): java.lang.ExceptionInInitializerError
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.javacv.ffmpeg.ZT_FFMPEG_JAVACVActivity.onCreate(ZT_FFMPEG_JAVACVActivity.java:19)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.os.Handler.dispatchMessage(Handler.java:99)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.os.Looper.loop(Looper.java:123)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at android.app.ActivityThread.main(ActivityThread.java:4627)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.reflect.Method.invokeNative(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.reflect.Method.invoke(Method.java:521)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at dalvik.system.NativeStart.main(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175): Caused by: java.lang.ExceptionInInitializerError
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.Class.classForName(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.Class.forName(Class.java:235)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacpp.Loader.load(Loader.java:334)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacv.cpp.opencv_highgui.<clinit>(opencv_highgui.java:91)
07-16 16:38:33.190: E/AndroidRuntime(27175):    ... 14 more
07-16 16:38:33.190: E/AndroidRuntime(27175): Caused by: java.lang.ExceptionInInitializerError
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.Class.classForName(Native Method)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.Class.forName(Class.java:235)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacpp.Loader.load(Loader.java:334)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacv.cpp.opencv_imgproc.<clinit>(opencv_imgproc.java:96)
07-16 16:38:33.190: E/AndroidRuntime(27175):    ... 18 more
07-16 16:38:33.190: E/AndroidRuntime(27175): Caused by: java.lang.UnsatisfiedLinkError: Library jniopencv_core not found
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.Runtime.loadLibrary(Runtime.java:461)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at java.lang.System.loadLibrary(System.java:557)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:444)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacpp.Loader.load(Loader.java:368)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacpp.Loader.load(Loader.java:315)
07-16 16:38:33.190: E/AndroidRuntime(27175):    at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:131)
07-16 16:38:33.190: E/AndroidRuntime(27175):    ... 22 more

My source code

package com.javacv.ffmpeg;
import static com.googlecode.javacv.cpp.opencv_highgui.cvLoadImage;
import java.io.File;
import java.util.ArrayList;
import static com.googlecode.javacv.cpp.opencv_highgui.CvVideoWriter;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.provider.MediaStore.Images;
import android.util.Log;
import com.googlecode.javacpp.annotation.ByPtrPtr;
import com.googlecode.javacpp.annotation.ByVal;
import com.googlecode.javacv.cpp.opencv_core;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
public class ZT_FFMPEG_JAVACVActivity extends Activity {

    com.googlecode.javacv.FFmpegFrameRecorder recorder ;
    private String TAG="kljadf";
    private IplImage colorImage;
    private IplImage image_small;
    private File[] file;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


    //========== have used previously to convert the single image to movie =========
        /*opencv_core.IplImage image = cvLoadImage("/mnt/sdcard/image.jpg"); 


        com.googlecode.javacv.FFmpegFrameRecorder recorder = new com.googlecode.javacv.FFmpegFrameRecorder("/mnt/sdcard/test.3gp",256,256);
        try {
            recorder.setCodecID(5);
            recorder.setFormat("3gp");
            recorder.setPixelFormat(0);
            recorder.start();
            for (int i=0;i<10;i++)
              {
                recorder.record(image);
              }
            recorder.stop();
           }
        catch (Exception e){
            e.printStackTrace();
          }*/

//========== have used previously to convert the single image to movie =========

       ArrayList<File>iamges=new ArrayList<File>();

       iamges.add(new File("mnt/sdcard/image"));
       iamges.add(new File("mnt/sdcard/image.png"));

       File[]  file=iamges.toArray(new File[iamges.size()]);
       file=iamges.toArray(new File[iamges.size()]);
       writeMovie(file,"Rajesh.mp4");
    }

@SuppressLint("ParserError") public void writeMovie(File[] files, String name) {

        double fps = 30;            
        int sas =com.googlecode.javacv.cpp.opencv_highgui.CV_FOURCC('U', '2', '6', '3');

        CvVideoWriter writer = com.googlecode.javacv.cpp.opencv_highgui.cvCreateVideoWriter(name,sas, fps, new com.googlecode.javacv.cpp.opencv_core.CvSize(640,480), -1); //CV_LOAD_IMAGE_UNCHANGED values is -1 
        if (writer == null) { 
                Log.e(TAG, "Can not create Writer!"); 
        } 
        for (File list:files) { 
            colorImage = cvLoadImage(list.toString(), 1); //CV_LOAD_IMAGE_COLOR =value for this=1 sp replaced by 1  
            if (colorImage == null) { 
                    Log.e(TAG, "Color Image is NULL!"); 
            } 
            image_small = opencv_core.cvCreateImage(opencv_core.cvSize(640, 480), colorImage.depth(), 4); //colorImage.nChannels()=4 as per jar file

            //or whatever color depth/channel number you need... 
            if (image_small == null) { 
                    Log.e(TAG, "Image Small is NULL!"); 
            } 
            com.googlecode.javacv.cpp.opencv_imgproc.cvResize(colorImage, image_small, 1);  //CV_INTER_LINEAR==1 
            if (writer != null) { 
                    cvWriteFrame(writer, image_small); 
            } else { 
                    Log.e(TAG, "Can not write frame, No writer!"); 
            } 
            opencv_core.cvReleaseImage(colorImage); 
            opencv_core.cvReleaseImage(image_small); 
        } 
        cvReleaseVideoWriter(writer); 
        finish(); 
} 

    public static native void cvReleaseVideoWriter(@ByPtrPtr CvVideoWriter paramCvVideoWriter);
    public static native int cvWriteFrame(CvVideoWriter paramCvVideoWriter, opencv_core.IplImage paramIplImage);
    public static native CvVideoWriter cvCreateVideoWriter(String paramString, int paramInt1, double paramDouble, @ByVal opencv_core.CvSize paramCvSize, int paramInt2);

**

Placed all the .so files in both libs/armeabi and libs/armeabi_v7 folder . Please help me fix this issue.

Thanks .

Do you have in your class which wants to use the library:

static {
   System.loadLibrary("yourlibname")
}

That name is supposed to be without the prefix lib and without the .so extension

You have an error which is a mark (in my oppinion)

07-16 16:38:33.190: E/AndroidRuntime(27175): java.lang.ExceptionInInitializerError

if you have not loaded the lib you would have seen unsatisfied link error but when the ExceptionInInitializerError is shown it usually means that the version of the NDK which was used to build the library is not compatible with the device.

try to : 1. check the ndk version vs the version of the emulator/devices you're using 2. if you're not using the official NDK check if the ndk version you have is compatible with the version you're using 3. test with the latest SDK to see if it runs (in case it does the problem is one of the above)

Also, case 2 is that you have library dependancy, like ie when loading cusombuilt open SSL in order to load the libssl.so you need to first load libcrypto.so since the ssl lib is linked to the crypto lib.

You should be aware of any inner-library dependencies you have.

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