5

First and foremost, my application generally works. I have numerous clients on all four 32-bit CPU/ABIs, and they have no trouble running the app. The native library is built for all four architectures. The library is there, the methods are all in place and named right. And yet, I'm getting exception reports ever once in a while that a native library can't be loaded:

java.lang.UnsatisfiedLinkError: Couldn't load foo from loader
dalvik.system.PathClassLoader [DexPathList[[zip file "/data/app/com.myapp-1.apk"],
nativeLibraryDirectories=[/data/app-lib/com.myapp-1, /vendor/lib, /system/lib]]]:
findLibrary returned null

I can't reproduce this, neither on the emulator nor in several devices that I've got access to. I've got reports with this exception from the following devices:

Sony Xperia LT29i (Android 4.3)
Sony Xperia C5303 (Android 4.3)
LG Optimus E405 (Android 2.3.6)

And it's very specific. I have 27 reports so far, but only those three devices. All those are armeabi-v7a devices, not sure if it matters.

Any ideas, please?

EDIT: got some logcat from an Optimus:

I/ActivityManager(23495): process name to start: com.myapp
I/ActivityManager(23495): Start proc com.myapp for activity com.myapp/.Main: pid=5755 uid=10078 gids={3003, 1015, 1007}

That's it. Nothing below that would indicate the error.

Seva Alekseyev
  • 59,826
  • 25
  • 160
  • 281
  • Do you have access to the logcat output, or just the exception? If there's a `dlopen()` problem it will appear in the log before the exception. – fadden Feb 23 '14 at 16:50
  • I dump logcat. Can't find anything relevant. – Seva Alekseyev Feb 23 '14 at 16:51
  • 1
    FWIW, there was a general problem fixed in 4.3, but there remain scattered reports of something similar failing. If you look at https://code.google.com/p/android/issues/detail?id=35962#c50 you'll see another developer with similar issues. The original bug affected app updates; can you confirm whether this is happening after install/update, or just generally at app launch? – fadden Feb 23 '14 at 16:58
  • Can't confirm either way. It's just an app run from where I sit. I've got some first_run and first_run_of_this_version logic, but never cared to dump that into exception logs. – Seva Alekseyev Feb 23 '14 at 17:16
  • Got some feedback from a user - it appeared after a version upgrade, uninstall/reinstall helped her. Sounds like that bug. Make an answer, I'll accept. – Seva Alekseyev Mar 02 '14 at 16:06
  • Written up as an answer. – fadden Mar 02 '14 at 22:29
  • http://stackoverflow.com/questions/18111739/why-do-some-android-phones-cause-our-app-to-throw-an-java-lang-unsatisfiedlinker - here are some good explanations on the topic – Smileek Apr 08 '14 at 07:23

3 Answers3

2

A widespread problem affecting app updates was fixed in 4.3, but it appears the problem has not entirely gone away. Recent updates to the bug call out Xperia devices in particular. Uninstall + reinstall by the end user should work around the problem.

fadden
  • 51,356
  • 5
  • 116
  • 166
  • Now I catch the exception and display a "Please uninstall and reinstall" message upon the main activity's startup. Better than nothing... – Seva Alekseyev Mar 04 '14 at 01:21
  • Users manually installing the wrong version of apps seems to have contributed to the problem; see https://medium.com/keepsafe-engineering/the-perils-of-loading-native-libraries-on-android-befa49dce2db . – fadden May 29 '18 at 14:52
2

Uninstall and reinstall works, but you can lose users, unfortunatly. To solve this issue in my project im ussing solution from chromium, its not perfect but looks like it works:

try {
        System.loadLibrary("YourLib");
    } catch (UnsatisfiedLinkError e) {

        System.load("YourLibPath");
    }
Alexander
  • 497
  • 6
  • 19
  • Where "YourLibPath" is...? – Seva Alekseyev Apr 22 '14 at 12:36
  • "/data/data//lib/foo.so" try something like this – Alexander Apr 22 '14 at 19:12
  • "Something like this"? Is that what you have in your project? This issue is extremely hard to test, you see. – Seva Alekseyev Apr 22 '14 at 19:14
  • 1
    i don't know path for your ndk lib folder, i think its like in link above,but you should change and "foo.so". In my project it was "/data/data/ru.mms.softphone/lib/libjni.so". At first try to load lib with System.load to test hardcoded path, and if it works use this construction. – Alexander Apr 22 '14 at 19:30
-1

I had put System.loadLibrary("libMyLibrary") which returned null. I changed it to System.loadLibrary("MyLibrary") and it worked.

luckyreed76
  • 185
  • 2
  • 8