当我在真实设备(中兴通讯,Android 4.2.2)上运行以下代码时出现错误:
_tessApi = new TessBaseAPI();
_tessApi.setDebug(false);
try {
_tessApi.init(Environment.getExternalStorageDirectory().getPath(), "chi_sim");
_useOcr = true;
} catch (Exception ex) {
_useOcr = false;
}
testRunner中的错误:
java.lang.UnsatisfiedLinkError: Couldn't load lept from loader dalvik.system.PathClassLoader[DexPathList[[
zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/uiautomator.jar", zip fi
le "/data/local/tmp/AutoRunner.jar"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]: findLibrary re
turned null
at java.lang.Runtime.loadLibrary(Runtime.java:366)
at java.lang.System.loadLibrary(System.java:514)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)
at com.base.jqhelper.initOCR(jqhelper.java:38)
at com.tieba.AddFriend.Initialization(AddFriend.java:328)
at com.tieba.AddFriend.testRunner(AddFriend.java:43)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.start(UiAutomatorTestRunner.java:144)
at com.android.uiautomator.testrunner.UiAutomatorTestRunner.run(UiAutomatorTestRunner.java:87)
at com.android.commands.uiautomator.RunTestCommand.run(RunTestCommand.java:90)
at com.android.commands.uiautomator.Launcher.main(Launcher.java:83)
at com.android.internal.os.RuntimeInit.nativeFinishInit(Native Method)
at com.android.internal.os.RuntimeInit.main(RuntimeInit.java:235)
at dalvik.system.NativeStart.main(Native Method)
我正在将项目打包到AutoRunner.jar中并将jar推送到真实设备。问题似乎是无法从设备加载liblept.so和libtess.so文件。
答案 0 :(得分:0)
我在这里找到了解决方案:
打开cmd然后执行:adb push ...\liblept.so system/lib
和adb push ...\libtess.so system/lib
(文件路径位于tess-two
文件夹下)
更改代码:
System.loadLibrary("lept");
System.loadLibrary("tess");
为:
System.load("/system/lib/liblept.so");
System.load("/system/lib/libtess.so");