Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnsatisfiedLinkError #51

Closed
ghost opened this issue Apr 9, 2014 · 54 comments
Closed

UnsatisfiedLinkError #51

ghost opened this issue Apr 9, 2014 · 54 comments

Comments

@ghost
Copy link

ghost commented Apr 9, 2014

On the phone (Galaxy S (GT-I9000) and Xperia T (LT30p) running 4.4 and 4.3) of two of my friends I from time to time get this strange error that crashes the app:

java.lang.UnsatisfiedLinkError: Couldn't load gif from loader dalvik.system.PathClassLoader[DexPathList[[zip file "/data/app/org.felikz.appname.s-1.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]]: findLibrary returned null
at java.lang.Runtime.loadLibrary(Runtime.java:358)
at java.lang.System.loadLibrary(System.java:526)
at pl.droidsonroids.gif.GifDrawable.<clinit>(Unknown Source)
at org.felikz.ui.webservice.views.AnimatedTouchableImageView.setImageFile(Unknown Source)
at org.felikz.ui.webservice.views.WebItemView.setProItem(Unknown Source)
at org.felikz.ui.webservice.views.WebItemView$3$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5142)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)

Usually this works fine. Could this be a problem of the library or rather an android bug? Thanks!

@koral--
Copy link
Owner

koral-- commented Apr 11, 2014

Time to time means randomly when running installed application or some compilations are generating broken apk (which causes an error every time it runs) or maybe there isn't any schema?

@ghost
Copy link
Author

ghost commented Apr 11, 2014

No, that is all the same compiled and built apk file, which is works mostly but rarely not. I wasn't able to see any pattern.

@koral--
Copy link
Owner

koral-- commented Apr 12, 2014

I think it cannot be problem in the library.
AFAIK findLibrary may return null if incorrect library name was specified in System.loadLibrary(), precisely there is no matching .so file or such file cannot be opened.
If name would be incorrect (or .so file would not be included in APK) then error will be thrown every time.

@ghost
Copy link
Author

ghost commented Apr 12, 2014

Okay, I also think that's the case. Just wanted to let you know!

@suwhs
Copy link

suwhs commented Aug 31, 2015

gradle bug :-\

mkdir app/src/main/lib 

solves this for me

@koral--
Copy link
Owner

koral-- commented Oct 15, 2015

@koral--
Copy link
Owner

koral-- commented Nov 9, 2015

For anyone searching for the issue findLibrary returned null:
It looks like, there is just a problem with native libraries on some devices:
https://medium.com/keepsafe-engineering/the-perils-of-loading-native-libraries-on-android-befa49dce2db
https://codereview.chromium.org/200753002/patch/280001/260004

If someone confirms that mentioned workaround works, I'll add it to the library.

@fgatti675
Copy link

I started having the UnsatisfiedLinkError and I found out that adding this in my gradle build was causing it:

    classpath 'com.google.gms:google-services:1.5.0-beta2'

Problem is... I need it! Any ideas? :)

@koral--
Copy link
Owner

koral-- commented Nov 10, 2015

Interesting I'll check this.

That plugin parses JSON from Google API console and generates for you string resources containing stuff like ids for GCM or Google Analytics, API key for Google Maps etc. The same effect can be achieved by manual copy-pasting that values.

Not sure how can it be related to UnsatisfiedLinkError maybe because it depends on beta version of com.android.tools.build:gradle artifact which has some bug related to native library packaging?

I think it is good idea to try with last stable (non-beta) version of google-services.

@dabo248
Copy link

dabo248 commented Nov 11, 2015

I'm also getting a UnsatisfiedLinkError:

Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: soinfo_link_image(linker.cpp:1635): could not load library "libpl_droidsonroids_gif.so" needed by "libpl_droidsonroids_gif_surface.so"; caused by load_library(linker.cpp:745): library "libpl_droidsonroids_gif.so" not found

It's working on my xperia z3 compact but on a nexus 4 with an older android version I'm getting this error.

@koral--
Copy link
Owner

koral-- commented Nov 11, 2015

@David145 Unfortunately I could not reproduce that on available device, but according that SO post: http://stackoverflow.com/questions/28806373/android-4-2-ndk-library-loading-crash-load-librarylinker-cpp750-soinfo-l there is a workaround for your issue.

Could you try adding System.loadLibrary("pl_droidsonroids_gif"); somewhere before using GifTextureView eg. in onCreate() of your Application or in static initializer block of an Activity?

If it is working I can add include it in library.

@dabo248
Copy link

dabo248 commented Nov 11, 2015

Tried it and added to the onCreate( ) of my main activity, but still getting the same error. I have no clue, what could be the problem, because it worked fine about two weeks ago when I tested it on the same device. It's on android 4.2.2.

Maybe this can help us?

My HTC One ordered from Google Play arrived, and... mystery solved! The same crash happened also on the original Android 4.2.2 from Google Play. The problem was my library name: cld, which produces a shared library named libcld.so. Apparently the system has another shared library with the same name, where the methods I expect are not present, of course... Probably some "plugin" loaded this other libcld.so into the process memory, and my own library was skipped. I renamed the native library and the program started working at once.

I was not aware of the possibility of such name clashes on different builds of Android... Did anyone reading this see a warning somewhere in NDK docs about it? I guess I'll prefix from now on all native libraries I create with my company name or something.

@koral--
Copy link
Owner

koral-- commented Nov 12, 2015

Was your app been updated during that 2 weeks or it was the same installation and just stopped working?

@dabo248
Copy link

dabo248 commented Nov 12, 2015

Did a lot of things on the app, so it definitely changed, but I can't tell what exactly causes that. The OS on the device stayed the same.

@koral--
Copy link
Owner

koral-- commented Nov 13, 2015

@David145 so, that may be the same case as described here:
https://medium.com/keepsafe-engineering/the-perils-of-loading-native-libraries-on-android-befa49dce2db
and here:
https://codereview.chromium.org/200753002/patch/280001/260004

I've just added slightly modified ReLinker. To use it call WorkaroundLibraryLoader#loadLibraries() before using GifTextureView. Available in version 1.1.11-SNAPSHOT.

Waiting for some feedback.

@dabo248
Copy link

dabo248 commented Nov 15, 2015

@koral-- Sorry for waiting, wasn't here on the weekend. Just tried to compile the SNAPSHOT and Android Studio is giving me "Failed to resolve: compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.11-SNAPSHOT".

@koral--
Copy link
Owner

koral-- commented Nov 16, 2015

You need to add maven snapshot repository in build.gradle:
maven{ url('https://oss.sonatype.org/content/repositories/snapshots')} in repositories block (NOT inside buildscript).

@dabo248
Copy link

dabo248 commented Nov 16, 2015

@koral-- Alright, did that, using WorkaroundLibraryLoader.loadLibraries(this); in my onCreate() method, right before using the gifs aand it works great now, all good. Thanks for helping so fast! :-)

How do you think you will implement that workaround in a release version of the library?

@koral--
Copy link
Owner

koral-- commented Nov 16, 2015

Yes, not sure yet if it will be exactly the same code as in snapshot but something similar will be included.

@DecentCow
Copy link

@koral-- Hi Koral, it does not work for me. I'm getting this error " dlopen failed: library "/data/data/com.demo.dev/app_lib/libpl_droidsonroids_gif.so" not found"

@koral--
Copy link
Owner

koral-- commented Nov 16, 2015

@DecentCow could you post complete stacktrace?

@koral-- koral-- reopened this Nov 16, 2015
@DecentCow
Copy link

@koral-- here's the stacktrace:

11-16 23:30:13.144 32632-32632/com.demo.dev E/art: dlopen("/data/data/com.demo.dev/app_lib/libpl_droidsonroids_gif.so", RTLD_LAZY) failed: dlopen failed: library "/data/data/com.demo.dev/app_lib/libpl_droidsonroids_gif.so" not found
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime: FATAL EXCEPTION: main
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime: Process: com.demo.dev, PID: 32632
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime: java.lang.UnsatisfiedLinkError: dlopen failed: library "/data/data/com.demo.dev/app_lib/libpl_droidsonroids_gif.so" not found
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at java.lang.Runtime.load(Runtime.java:331)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at java.lang.System.load(System.java:981)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:77)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at pl.droidsonroids.gif.WorkaroundLibraryLoader.loadLibraries(WorkaroundLibraryLoader.java:13)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at com.demo.DemoApplication.onCreate(DemoApplication.java:68)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4588)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.app.ActivityThread.access$1600(ActivityThread.java:154)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:102)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:135)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5289)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Native Method)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:372)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
11-16 23:30:13.146 32632-32632/com.demo.dev E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)

dev is a build variant (maybe it will help you)

@koral--
Copy link
Owner

koral-- commented Nov 17, 2015

@DecentCow in your case even Relinker did not manage to load native library. Is your scenario the same as described here: https://github.com/koral--/android-gif-drawable/issues/51#issuecomment-155982018? (library loading stopped working after app update) or that is a fresh app installation and loading does not work from the beginning?

@DecentCow
Copy link

@koral-- Yes, it worked before but now after some updates it does work anymore.

@FaizVisram
Copy link

Also might be worth noting that I tried the 1.1.11 SNAPSHOT and .8, .9 and .10

@FaizVisram
Copy link

@xiphirx yes there is, in /data/data/[package]/lib/

@xiphirx
Copy link

xiphirx commented Nov 25, 2015

so libpl_droidsonroids_gif.so is in your /lib/ folder, and it still cannot find it? How are you loading the library in your code?

@koral--
Copy link
Owner

koral-- commented Nov 25, 2015

@FaizVisram if your stacktrace is the same as last in this thread: https://github.com/koral--/android-gif-drawable/issues/51#issuecomment-157193898 then you are not using the latest snapshot but previous one.
There are 2 snapshots with version 1.0.11: https://oss.sonatype.org/content/repositories/snapshots/pl/droidsonroids/gif/android-gif-drawable/1.1.11-SNAPSHOT/. The latest one has been uploaded on Mon Nov 23 01:22.
Please redownload or clear gradle/maven cache.

@FaizVisram
Copy link

@koral-- Ah, that did it. I cleared the Gradle cache and it seems to be working for me, I'll let you know if my QA says otherwise (won't get to it until tomorrow at least).

@FaizVisram
Copy link

@koral-- the latest version passed our QA, thought you'd like to know :) Thanks for all your help guys, and thanks for the library too :D

koral-- added a commit that referenced this issue Nov 29, 2015
@koral--
Copy link
Owner

koral-- commented Nov 29, 2015

@David145 @FaizVisram (and others using 1.1.11-SNAPSHOT version), there will be little changes in release version. WorkaroundLibraryLoader#loadLibraries() has been replaced by LibraryLoader#initialize(). Current snapshot is called 1.1.11-r1-SNAPSHOT.

@koral--
Copy link
Owner

koral-- commented Dec 2, 2015

OK, finally this issue can be closed. Workaround should work even without calling LibraryLoader#initialize(). In such case there is fallback to hidden ActivityThread#currentApplication() as source of Context. However calling initialize() is recommended. Info has been added to README.

@koral-- koral-- closed this as completed Dec 2, 2015
@afaucogney
Copy link

I still get an issue:

Library libpl_droidsonroids_gif.so not found in APK file

I have the 1.1.11-r1-SNAPSHOT
Put:

LibraryLoader.initialize(this);

in my Activity OnCreate.

And then add this in my Fragment.

GifDrawable gifFromAssets = null;
try {
   gifFromAssets = new GifDrawable(getActivity().getAssets(), "glass_shaking.gif");
} catch (IOException e) {
   e.printStackTrace();
}

@xiphirx
Copy link

xiphirx commented Dec 2, 2015

Library libpl_droidsonroids_gif.so not found in APK file means the library is not in your App's APK, so you have a packaging issue.

@afaucogney
Copy link

I do not know what it is really mean. I just use the standard way. However my app is multi-dex (if that can help).

@xiphirx
Copy link

xiphirx commented Dec 2, 2015

Your APK file does not have the library file inside of it. You can verify this by renaming your APK to a ZIP file and unpacking it.

@afaucogney
Copy link

Yes, nothing inside, but why ?

@xiphirx
Copy link

xiphirx commented Dec 2, 2015

There can be a lot of reasons, however its not related to this issue and its not an issue with the library.

@afaucogney
Copy link

is the lib should normally be added from Gradle dependency compile function ? Or is there something else to do ?

@koral--
Copy link
Owner

koral-- commented Dec 3, 2015

@afaucogney all AARs published to maven repositories contain libraries and they should be placed into resulting APK (in lib directory) by default.
If there is no such directory in APK then it looks like a misconfiguration in build.gradle like empty abiFilter.
Could you post contents of your build.gradle (including top-level one if present) and version of Gradle (wrapper) which you are using?

@afaucogney
Copy link

@koral-- this is my first native lib integration, feel free to think basic issue !

I just follow the Readme, so

  1. put compile 'pl.droidsonroids.gif:android-gif-drawable:1.1.11' into my app gradle file.
  2. init the lib LibraryLoader.initialize(this);
  3. use the lib
GifDrawable gifFromAssets = null;
try {
   gifFromAssets = new GifDrawable(getActivity().getAssets(), "glass_shaking.gif");
} catch (IOException e) {
   e.printStackTrace();
}

Nothing else added up to now.
Nothing about abiFilter.

My app is a multi-dex
When I unzip, I have a lib folder with 2 lib (*.so), for various plateform, but not the one of this project.
NDK is not installed in AS
Gradle wrapper is 2.8
Gradle Android Plugin is 1.3.1

@koral--
Copy link
Owner

koral-- commented Dec 3, 2015

There should be 7 subdirectories in lib each for separate architecture by default. Each of them should contain 2 so files. There must be also at least one directory corresponding to architecture supported by target device in resulting APK to work.
This is an exaple content of APK:

   29772  12-03-2015 21:00   lib/x86/libpl_droidsonroids_gif.so
     9280  12-03-2015 21:00   lib/x86/libpl_droidsonroids_gif_surface.so
    30128  12-03-2015 21:00   lib/arm64-v8a/libpl_droidsonroids_gif.so
     9624  12-03-2015 21:00   lib/arm64-v8a/libpl_droidsonroids_gif_surface.so
    29884  12-03-2015 21:00   lib/armeabi-v7a/libpl_droidsonroids_gif.so
    13488  12-03-2015 21:00   lib/armeabi-v7a/libpl_droidsonroids_gif_surface.so
    73492  12-03-2015 21:00   lib/mips/libpl_droidsonroids_gif.so
    71132  12-03-2015 21:00   lib/mips/libpl_droidsonroids_gif_surface.so
    41552  12-03-2015 21:00   lib/mips64/libpl_droidsonroids_gif.so
    10360  12-03-2015 21:00   lib/mips64/libpl_droidsonroids_gif_surface.so
    33968  12-03-2015 21:00   lib/armeabi/libpl_droidsonroids_gif.so
    17572  12-03-2015 21:00   lib/armeabi/libpl_droidsonroids_gif_surface.so
    34416  12-03-2015 21:00   lib/x86_64/libpl_droidsonroids_gif.so
     9816  12-03-2015 21:00   lib/x86_64/libpl_droidsonroids_gif_surface.so

If you have only 2 directories inside lib then something must cause stripping other ones.
NDK is needed only to compile so files. Multi-dex should not be related since so files are not packaged into dex files.

What are the names of that 2 directories which you have in APK?

@koral--
Copy link
Owner

koral-- commented Dec 31, 2015

@afaucogney issue similar to yours: https://github.com/koral--/android-gif-drawable/issues/237#issuecomment-168169705
Solution was to update gradle plugin version.

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

No branches or pull requests

9 participants