Android Jni .so文件ExceptionInInitializerError和UnsatisfiedLinkError:找不到库jniopencv_core

时间:2012-07-17 06:18:12

标签: android opencv java-native-interface

我正在开发一个基于Javacv的Android项目。我已经完成了项目Readme.txt文件中给出的说明。将所有.so文件放在libs / armeabi文件夹中。并使用以下行将图像转换为电影。 但得到了以下日志。

* 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

我的源代码

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();
          }*/

// ==========之前用过将单张图片转换为电影=========

       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);

**

将所有.so文件放在libs / armeabi和libs / armeabi_v7文件夹中。 请帮我解决这个问题。

谢谢。

2 个答案:

答案 0 :(得分:0)

你班上有没有想要使用这个库的内容:

static {
   System.loadLibrary("yourlibname")
}

该名称应该没有前缀lib且没有.so扩展名

答案 1 :(得分:0)

你有一个错误,这是一个标记(在我的意见中)

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

如果你还没有加载lib你会看到不满意的链接错误,但是当 显示ExceptionInInitializerError它通常意味着用于构建库的NDK版本与设备不兼容。

尝试: 1.检查ndk版本与您正在使用的仿真器/设备的版本 2.如果您没有使用官方NDK检查您的ndk版本是否与您正在使用的版本兼容 3.使用最新的SDK进行测试以查看它是否运行(如果问题是上述问题之一)

另外,情况2是您具有库依赖性,例如,当加载cusombuilt打开SSL以加载libssl时,您需要首先加载libcrypto.so,因为ssl lib链接到加密lib。

您应该了解您拥有的任何内部库依赖项。