如何在eclipse中将现有的.so文件添加到android项目中?

时间:2012-02-20 20:22:19

标签: android ocr

正如标题所说:我想将现有的libocr.so添加到我的android项目中。我刚刚在项目根目录中创建了/libs/armeabi/libocr.so,我想将它添加为库。

感谢

dmytrodanylyk:我已尝试过您的解决方案,但当我尝试执行System.loadLibrary(“ocr”);

发生异常:


02-21 16:50:52.799: ERROR/AndroidRuntime(15073): FATAL EXCEPTION: main
02-21 16:50:52.799: ERROR/AndroidRuntime(15073): java.lang.ExceptionInInitializerError
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at net.gummo.OCRTestActivity.onCreate(OCRTestActivity.java:20)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.app.ActivityThread.access$2300(ActivityThread.java:135)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.os.Looper.loop(Looper.java:144)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at android.app.ActivityThread.main(ActivityThread.java:4937)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at java.lang.reflect.Method.invokeNative(Native Method)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at java.lang.reflect.Method.invoke(Method.java:521)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at dalvik.system.NativeStart.main(Native Method)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073): Caused by: java.lang.UnsatisfiedLinkError: Library ocr not found
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at java.lang.Runtime.loadLibrary(Runtime.java:461)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at java.lang.System.loadLibrary(System.java:557)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     at net.gummo.OCR.(OCR.java:1067)
02-21 16:50:52.799: ERROR/AndroidRuntime(15073):     ... 14 more 


1 个答案:

答案 0 :(得分:1)

以下是示例:

public static boolean loadNativeLibrary() {

    try {

        Log.i(TAG, "Attempting to load library: " + LIBRARY_NAME);
        System.loadLibrary(LIBRARY_NAME);

    } catch (Exception e) { 
        Log.i(TAG, "Exception loading native library: " + e.toString());
        return false;
    }

    return true;
}