2012-02-20 56 views
-1

正如標題所說:我想添加現有的libocr.so到我的android項目。我剛剛在項目根目錄下創建了/libs/armeabi/libocr.so,我想將它添加爲庫。如何將eclipse中現有的.so文件添加到android項目中?

感謝

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

這裏是例子:

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; 
} 
+0

dmytrodanylyk:不要緊,其中libocr.so位於項目或它必須是根或類似林達一些特殊的文件夾。 lib還是其他? – falconseye 2012-02-20 21:06:46

+0

.so庫文件通常位於project_root_dir/libs子文件夾中。另外,它們通常位於描述其體系結構的其他子文件夾中(例如,project_root_dir/libs/armeabi/libpdfview2.so)。 – 2012-02-21 11:34:09

+0

嘗試使用搜索優先:http://stackoverflow.com/questions/8650472/how-do-i-import-a-native-library-so-file-into-eclipse – 2012-02-21 11:34:31

相關問題