Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Native function no implementation found

Problem: 20% of users are receiving:

Fatal Exception: java.lang.UnsatisfiedLinkError
No implementation found for java.lang.String com.example.utils.API.getHashString(android.content.Context) (tried Java_com_example_utils_API_getHashString and Java_com_example_utils_API_getHashString__Landroid_content_Context_2)

For other 80% app working perfectly, no exception on my test devices as well. Can't figure out what's the problem.

EDIT1: Library loads perfectly on splash screen. No exception on that point.

static { System.loadLibrary("my-lib"); }

EDIT2: Just reproduced the error. It is absolutely random. App function call works fine, and at some time it starts failing. The only fix is re-installing the app.

like image 1000
Stanislav Parkhomenko Avatar asked Feb 10 '17 08:02

Stanislav Parkhomenko


3 Answers

Following my comment and later comments from @stanislav-parkhomenko, I'm reposting it as an answer. Thanks!

My comment:

Where is the static {...} block located? A possible reason for this could be that the code is not executed before some calls.

And later confirmed by himself that this was the cause:

The problem was in library initialization. Splash screen run not always, because of sharing functionality, thats why some times library did not load.

Thanks to Xavier Rubio Jansana for advice, which cured my blindness.

Glad it helped!

like image 121
Xavier Rubio Jansana Avatar answered Oct 17 '22 17:10

Xavier Rubio Jansana


This error is caused by method signature mismatch between Java and native library you are loading. It is likely that 20% of users have different version of library file with same name. If it is your own library try giving it relatively unique name and load it from absolute path to reduce chance of name conflict.

like image 31
Vlad Ilyushchenko Avatar answered Oct 17 '22 19:10

Vlad Ilyushchenko


It looks like it's trying to load a native library, and there isn't support in Android Gradle for native code yet. You should double-check the docs for your library to confirm; I tried to look it up but it looks like it's a commercial library without publicly accessible docs.

You could just put the .so files into jniLibs folder in src/main. This was introduced in AS 0.7.2

As a sample, see this from @CommonsWare, or see this page for official samples (scroll to the bottom of page)

Yes Still no support for native library in Android gradle.Just I followed simple hack.It works great.Check this

like image 1
Shailesh Avatar answered Oct 17 '22 18:10

Shailesh