简体   繁体   English

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

[英]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 . 我正在一个基于Javacv的Android项目。我已按照项目Readme.txt文件中的说明进行操作。 Placed all the .so files in libs/armeabi folder. 将所有.so文件放在libs / armeabi文件夹中。 and have used the following lines to convert the images to movie . 并已使用以下行将图像转换为电影。 But got following log. 但是得到了以下日志。

* Logcat * * 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) { @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 . 将所有.so文件放置在libs / armeabi和libs / armeabi_v7文件夹中。 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 该名称应该没有前缀lib且没有.so扩展名

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. 如果未加载该库,则将看到不满意的链接错误,但是当显示ExceptionInInitializerError时,通常意味着用于构建该库的NDK版本与该设备不兼容。

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) 尝试执行以下操作:1.检查ndk版本与使用的仿真器/设备的版本2.如果未使用官方NDK,请检​​查所拥有的ndk版本是否与所使用的版本兼容3。使用最新的SDK进行测试以查看其是否运行(如果发生问题,则是上述问题之一)

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. 同样,情况2是您具有库依赖性,例如,当加载cusombuilt open SSL以便加载libssl.so时,您需要首先加载libcrypto.so,因为ssl lib已链接到crypto lib。

You should be aware of any inner-library dependencies you have. 您应该知道您拥有的任何内部库依赖性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 带有.So库的Android NDK / JNI UnsatisfiedLinkError - Android NDK/JNI UnsatisfiedLinkError With .So library android UnsatisfiedLinkError:找不到库 - android UnsatisfiedLinkError: Library not found 找不到本机UnsatisfiedLinkError异常Android JNI的实现 - No Implementation found for native UnsatisfiedLinkError Exception Android JNI Android 库:java.lang.UnsatisfiedLinkError:dlopen 失败:找不到库“libgnustl_shared.so” - Android Library: java.lang.UnsatisfiedLinkError: dlopen failed: library "libgnustl_shared.so" not found java.lang.UnsatisfiedLinkError:dlopen 失败:找不到库“../../lib/libopencv_core.so” - java.lang.UnsatisfiedLinkError: dlopen failed: library "../../lib/libopencv_core.so" not found JNI和Android…UnsatisfiedLinkError - JNI and Android… UnsatisfiedLinkError 在 Android 中使用 jni:UNsatisfiedLinkError - Using jni in Android: UNsatisfiedLinkError JNI UnsatisfiedLinkError-Android - JNI UnsatisfiedLinkError - Android Android JNA UnsatisfiedLinkError: Native library (com/sun/jna/xxx/libjnidispatch.so) not found - Android JNA UnsatisfiedLinkError: Native library (com/sun/jna/xxx/libjnidispatch.so) not found java.lang.ExceptionInInitializerError原因:java.lang.UnsatisfiedLinkError:未找到库 - java.lang.ExceptionInInitializerError Caused by: java.lang.UnsatisfiedLinkError: Library not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM