How to add Mobile OCR to a Gradle project in Android

  • 1.4K Views
  • Last Post 10 February 2016
David Aguiar posted this 09 February 2016

I have an Android project using Gradle and I want to add the library Mobile OCR Engine.

I add MobileOcrEngine.jar under libs folder and libMobileOcrEngine.so under libs/armeabi, following steps in documentation. I also add the gradle compile statement:

compile files('libs/MobileOcrEngine.jar')

Then, in my Application::onCreate method I add the following code (copied from example):

final DataSource assetDataSource = new AssetDataSource(getAssets());

final List<DataSource> dataSources = new ArrayList<>();
dataSources.add(assetDataSource);

Engine.loadNativeLibrary(); // ERROR HERE!
try {
  Engine.createInstance(dataSources,
                   new FileLicense(assetDataSource, LICENSE, APPLICATION_ID),
                   new Engine.DataFilesExtensions(PATTERNS_FILE_EXTENSION,
                                          DICTIONARIES_FILE_EXTENSION,
                                          KEYWORDS_FILE_EXTENSION));

  RecognitionContext.createInstance(this);
} catch (final IOException e) {
  Log.e("VrLApplication", "setupAbbyyEngine " + e.getMessage());
} catch (final License.BadLicenseException e) {
  Log.e("VrLApplication", "setupAbbyyEngine " + e.getMessage());
}

But when I run it, I get the following error:

02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime: FATAL EXCEPTION: main
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime: Process: prototype.vrleasing, PID: 1882
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime: java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/p.vrl-2/base.apk"],nativeLibraryDirectories=[/data/app/p.vrl-2/lib/arm, /vendor/lib, /system/lib]]] couldn't find "libMobileOcrEngine.so"
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at java.lang.Runtime.loadLibrary(Runtime.java:366)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at java.lang.System.loadLibrary(System.java:988)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at com.abbyy.mobile.ocr4.Engine.loadNativeLibrary(Engine.java:270)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at p.vrl.VrLApplication.setupAbbyyEngine(VrLeasingApplication.java:61)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at p.vrl.VrLApplication.onCreate(VrLeasingApplication.java:40)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1035)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4638)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.app.ActivityThread.access$1500(ActivityThread.java:155)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1378)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5343)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
02-08 12:41:36.931 1882-1882/p.vrl E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)

Any guess what am I doing wrong?

Order By: Standard | Newest | Votes
IvanPopov posted this 10 February 2016

We sent you the instructions as a response to your e-mail to ABBYY support regarding the same question.

Lonzak posted this 01 March 2016

You have to put the .so file in 'jniLibs' directory (e.g.the Sample\app\src\main\jniLibs\armeabi-v7a\*.so)

Close