Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI 'libjpgt.so' and 'liblept.so' w/ compile 'com.rmtheis:tess-two:6.0.0' #150

Closed
seantibb opened this issue Jun 6, 2016 · 23 comments

Comments

@seantibb
Copy link

seantibb commented Jun 6, 2016

Hey team awesome! I found an issue tonight that I can't seem to find a workaround for. I updated my application to call tess-two 6.0.0 from tess-two 5.4.1 and started getting the error below about being unable to load libjpgt.so and liblept.so. I reverted back to 5.4.1 and do not get the same error.

This is an app targeting Ice Cream Sandwich (min SDK 15) for an older device.

Any suggestions?

Stacktrace:

06-05 23:03:15.565 29589-29589/[redacted] D/dalvikvm: Trying to load lib /data/data/[redacted for security]/lib/liblept.so 0x4103ca50 06-05 23:03:15.565 29589-29589/[redacted] W/dalvikvm: Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI; 06-05 23:03:15.565 29589-29589/[redacted] D/AndroidRuntime: Shutting down VM 06-05 23:03:15.565 29589-29589/[redacted] W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40abb1f8) 06-05 23:03:15.573 29589-29589/[redacted] E/AndroidRuntime: FATAL EXCEPTION: main java.lang.ExceptionInInitializerError at [redacted].MainActivity.doOCR(MainActivity.java:561) at [redacted].MainActivity.onPictureTaken(MainActivity.java:417) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:689) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1936]: 104 could not load needed library 'libjpgt.so' for 'liblept.so' (load_library[1091]: Library 'libjpgt.so' not found) at java.lang.Runtime.loadLibrary(Runtime.java:370) at java.lang.System.loadLibrary(System.java:538) at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44) at [redacted].MainActivity.doOCR(MainActivity.java:561) at [redacted].MainActivity.onPictureTaken(MainActivity.java:417) at android.hardware.Camera$EventHandler.handleMessage(Camera.java:689) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) at dalvik.system.NativeStart.main(Native Method)

@rmtheis
Copy link
Owner

rmtheis commented Jun 9, 2016

Did you try doing a clean or File->Invalidate Caches and Restart?

@rmtheis
Copy link
Owner

rmtheis commented Jun 12, 2016

What happens when you go to run the test cases?

Please reopen this issue with more complete instructions on how to reproduce the problem.

@rmtheis rmtheis closed this as completed Jun 12, 2016
@seantibb
Copy link
Author

Steps to reproduce the error:

Run a functioning app using app/build.grade with:

compile 'com.rmtheis:tess-two:5.4.1'

Everything works fine

Update app/build.gradle to:
compile 'com.rmtheis:tess-two:6.0.1'

On the line of your code that calls "new TessBaseAPI()" error will be thrown.

Change app/build.gradle back to
compile 'com.rmtheis:tess-two:5.4.1'
and all is fine.

To try and resolve, I 1) invalidated caches and restarted, 2) ran clean build, 3) compiled and installed app on device.

Code to reproduce:

public static TessBaseAPI gTess = null;
if (getTess() == null) {
setTess(new TessBaseAPI());
}
public static synchronized void setTess(TessBaseAPI newTess) {
gTess = newTess;
}

Also, I tried finding the test cases, but since I am calling it from the build.gradle instead of downloading the source and importing as a module, I do not have the test cases available that I can find.

Thanks!

@rmtheis
Copy link
Owner

rmtheis commented Jun 15, 2016

Is your minSdkVersion at least 9?

@rmtheis rmtheis reopened this Jun 15, 2016
@seantibb
Copy link
Author

here's that piece of my app/build.gradle:

    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.rmtheis:tess-two:5.4.1'
compile project( ':libraries:opencv' )
}

5.4.1 works great, as soon as I change that to 6.0.1 I get the link error.

@rmtheis
Copy link
Owner

rmtheis commented Jun 15, 2016

After you change to 6.0.1, and you choose "Sync Now", do you get BUILD SUCCESSFUL?

@seantibb
Copy link
Author

I do. Everything appears fine in Android Studio. It's not until I actually run the app that it crashes.

@rmtheis
Copy link
Owner

rmtheis commented Jun 15, 2016

If you unzip your APK and look in its libs folder, do you see four *.so files available in each subfolder?

@seantibb
Copy link
Author

Yup, they're all there. Really strange :/

@rmtheis
Copy link
Owner

rmtheis commented Jun 15, 2016

Hmm... does it still happen if you remove OpenCV, or otherwise try a simplified version of your app?

@seantibb
Copy link
Author

Yup. The only change is that compile line in the build.gradle

@rmtheis
Copy link
Owner

rmtheis commented Jun 15, 2016

What I mean is that you should try removing unrelated parts of your app to narrow down what's causing the problem. I suspect the problem is somehow related to your setup or your code. For example, I can make this same change on my android-ocr project without hitting this error.

Are you able to create a simplified/minimal example that you can share on Github that demonstrates the problem?

@rmtheis
Copy link
Owner

rmtheis commented Jun 16, 2016

Also see #127.

@lhb2
Copy link

lhb2 commented Jun 24, 2016

with compile 'com.rmtheis:tess-two:6.0.1', I have same problem at Galaxy Nexus(4.2.2),but no problem at other device.
I think this is a bug.

@rmtheis
Copy link
Owner

rmtheis commented Jun 28, 2016

@seantibb @guoyong0423 which version of Android are you running on when you see this error?

@seantibb
Copy link
Author

@rmtheis API 15 here...Ice Cream Sandwich

@lhb2
Copy link

lhb2 commented Jul 6, 2016

the error reappeared at another device(4.1.2)

@giniedp
Copy link

giniedp commented Jul 13, 2016

same here.
Library works fine in version 5.4.1
Switching to 6.0.2 sopts working on a HTC One V with Android 4.1.2 (cyanogen mod)

minSdkVersion 16
targetSdkVersion 23

Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1916]:  1486 could not load needed library 'libjpgt.so' for 'liblept.so' (load_library[1118]: Library 'libjpgt.so' not found)
at java.lang.Runtime.loadLibrary(Runtime.java:370)
at java.lang.System.loadLibrary(System.java:535)
at com.googlecode.tesseract.android.TessBaseAPI.<clinit>(TessBaseAPI.java:44)

6.0.2 works fine on

  • Nexus 6 Android 6.0.1
  • Samsung Galaxy 4 Android 5.0.1
  • HTC One Mini Android 4.4.2

6.0.2 stopped working on

  • HTC One V Android 4.1.2 (cyanogen mod)
  • Nexus 7 Android 4.1.2

@rmtheis
Copy link
Owner

rmtheis commented Jul 15, 2016

It looks to me like this is a bug that occurs on devices running Android versions prior to 4.4 (KitKat). I don't think it's directly fixable from this project, but there are some options for a workaround:

  1. Remove libjpeg
  2. Support pre-KitKat Android by providing a new constructor TessBaseAPI(Context) that uses Relinker to work around the library loading problem
  3. Do a bug-fix 5.4.2 release and drop support for pre-KitKat Android going forward

@rmtheis
Copy link
Owner

rmtheis commented Jul 15, 2016

Also worth trying would be explicitly loading libjpeg, with the libraries in this order:

System.loadLibrary("jpgt");
System.loadLibrary("lept");
System.loadLibrary("tess");

@lhb2
Copy link

lhb2 commented Jul 15, 2016

Thank you very match!
It works fine when I add this code in my class:
static{
System.loadLibrary("jpgt");
System.loadLibrary("pngt");
System.loadLibrary("lept");
System.loadLibrary("tess");
}

@aneeshATgithub
Copy link

can u please help me??
#169

@parulsngh
Copy link

Its working fine for initial few api calls but getHOCRText() method responding very slow after continuous usage. The image I am passing for scanning is binarized image.
Is their any limit for api hits in a single day? Can't figure out the issue, plz help.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants