Application crashing due to java.lang.UnsatisfiedLinkError No Implementation Found - java

I am using external .so library files for my application. Upon trying to use them in my app, it started crashing for a function that is called in the code.Error pulled from crash log:
java.lang.UnsatisfiedLinkError No Implementation Found
Any assistance would be appreciated. I am running out of things to test with the code. My assumption of the issue is that it is not actually loading the library which to me would explain why no implementation could be found. I do call the function to load the library here. Code that is loading the library

Related

How to combine a standalone application with an Android application?

How do I combine a standalone Java application with an Android application?
I have a piece of code taken from the Google quick start examples that perform a task that I can't seem to be able to combine with my activity source code.
I'm of course talking about the following Google example: Sheet API, if I just add it as a standalone class and tell Android Studio to run this application, before my Android application, then it will produce what the code is suppose to do.
If I try to copy and paste the exact code into one of my activities it will give a couple of problems. One is that it can not find my keystore, another is a threading issue which I understand, another being that it can not find the credentials (even if the file is present), the newTrustedTransport-method call will be an issue, the setDataStoreFactory-method call will be an issue, file creation even with the correct uses-permissions and so on.
What is going on in the background that would make exactly the same source code work in one instance and not the other? What do I not know about Android Studio, and how an Android project works in the background for me having these issues?
I had an idea that I could just keep this standalone application as it is and store a file with the result that this Sheet example would provide me. But, since I do not have enough experience with Android Studio I have no idea if the result will be available for the actual Android application once it was made into a release. Will it? I can't save the output file generated by the Sheet example, under the res-folder, under the app module for some reason (scope?).
With other words... Can I have a standalone application, that is tasked to run before the Android application, to gather data and it will be doing this EACH time the Android application is run on a client? I feel like it would be stupid if the IDE would present this like this would actually work but then when the application is made into a release then the standalone application will not "follow" and be part of the release...
If I could just combine the source codes, I will not be having this issue at all. No examples online, neither Github or Youtube can provide me with answers on how to do this. Many examples online provide me with source code that is either out of date or just not what I'm looking for, and I really hate Google's way of explaining things. Just look at how they give code examples under this page: Google API Client Library for Java, and not give a full example where they would fit into the a project. Maybe all I need to make everything work is to use the code under "The library runs on Android 4.0 or higher (#Beta)."

Java application crashes when calling System.loadLibrary

I've used cygwin to build a dll (which depends on some openssl libraries). Now I'm trying to load the dll using System.loadLibrary. But at that point the application just exits with return code -1073740940.
There is no exception or information. The libraries path is set using -Djava.library.path=path/to/library.
Why is my application crashing without any errors? If there's an error in native code I'd get a message about that, right? And the only static variable I have for sure does not cause a crash.
EDIT
As it turns out, I can generalize this question: Are there any pitfalls when using cygwin to build a dll for the use in java?
Another thing I noticed is that loading the library sometimes causes an immediate exit and sometimes does not finish at all (it just keeps loading the library until I kill the application

Running android java's native libraries under linux

I have well-working simple android app(graphically does nothing, but calculates some data), that uses native libraries, those libraries is for x86, so I am hoping to make that code work under x86 ubuntu as a simple compiled java binary.
So after finding all library dependencies compiler tells me:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
lib/libgnustl_shared.so: lib/libgnustl_shared.so: undefined symbol: __sF
After a bit googling I found that __sF is some kind of android specified parameters array, that accesible in the android env(or elsewhere, I actually don't know).
libgnustl_shared.so depends from libm.so and libdl.so, that comes with ubuntu.
Should I try to find android x86 libm.so and libdl.so? Or try to implement some how __sF in java code?
(main point is to solve issue with libgnustl_shared.so, other libraries is written manually by my co-worker so I dont expect any harm from them)
I hope someone has the sacred knowledge to help me make it work. Appreciate any help.

OpenCV with Glassfish webapplication

I'm trying to develop a Java webapplication with Glassfish using JSF and OpenCV. I wrote some code which works fine on Java desktop application. However, when I try to implement it on Glassfish app it shows me an error UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J, when I use System.loadLibrary(Core.NATIVE_LIBRARY_NAME) before I get java.lang.UnsatisfiedLinkError: Native Library already loaded in another classloader.
I tried putting loading code into singleton - still this same situation. Tried to load singleton in different application and call it by Class.forName() - dll loaded but the application still doesn't work and the first error appears UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat(IIIDDDD)J.
I tested OpenCV 2.4.10, 2.4.11 and 3.0 versions under Glassfish 4 and Glassfish 4.1 servers. I'm working on Windows and using Netbeans.
Please help me because I got stuck and have no idea what else I can do with it.
Thank you in advance.

Calling System.loadLibrary twice for the same shared library

I have the situation when two jar libraries use the same shared library.
In each library "the main interface" class loads the .so file with System.loadLibrary.
My question is: if the user decides to use these two jar libraries in one project, would the second call to System.loadLibrary for the same .so file cause any exception? Or is it "somehowe handled" by the system to prevent shared libraries from being loaded twice? Or maybe there is a "commonly known pattern" to handle such situations?
The jni wrappers are targeted to be used on android. I am the author of both wrapper libs so answering you can assume full control on java sources.
According to the apidocs it should not be a problem: "If this method is called more than once with the same library name, the second and subsequent calls are ignored."
I've found one very narrow use case when this will be a problem.
If you are running Android system app, with android:sharedUserId="android.uid.system" in manifest, either pre-installed to the device, or signed with the platform certificate, and you are trying to call System.loadLibrary twice to load the same library (either by running the same app twice, or creating two separate system apps loading the same library), Android will reboot.
Invoking JNI method from this library, if it was not yet loaded, will not generate an exception when running inside android.uid.system process, as with normal Android app - it will reboot Android.
To prevent that, and find out if the library was already loaded, you can read file /proc/self/maps and search for your library name there. ClassLoader and reflection will not help here - they will show JNI methods as accessible even when the library is not yet loaded.
Note that you cannot do if (Runtime.getRuntime().exec("/system/bin/grep <library-name> /proc/self/maps").waitFor() == 0) - system process is forbidden from launching any external commands by SELinux, you will have to read the file from the Java code.
Another quirk is that the library must be preinstalled to device to the /system/lib directory - if you bundle the library with your app, and install the app to device, library will end up in /data/app/..../lib, and when you will try lo load it from /data partition, well you already guessed - Android will reboot.

Categories