Hello i'm using JNA to be able to use an external .dll(i don't have the header file but i have documentation thus the exposed function signatures).
I have managed to use my dll in a java project following the instructions here and now i'm trying to use the same thing on an android app.
I imporetd the jna jar in my libs and also added the jar in my buildpath and i'm getting an error
The library 'jna-3.5.1.jar' contains native libraries that will not run on the device.
The following libraries were found:
com/sun/jna/linux-amd64/libjnidispatch.so
com/sun/jna/darwin/libjnidispatch.jnilib
com/sun/jna/linux-i386/libjnidispatch.so
com/sun/jna/sunos-x86/libjnidispatch.so
com/sun/jna/sunos-amd64/libjnidispatch.so
com/sun/jna/sunos-sparc/libjnidispatch.so
com/sun/jna/sunos-sparcv9/libjnidispatch.so
Any ideas?
This deserves an answer...
Did you compile the lib you wanna use for android?
Why not write a JNI wrapper around those native libs, and invoke that from your android app?
Browse your jna.jar and delete the files displayed on your message :
com/sun/jna/linux-amd64/libjnidispatch.so
com/sun/jna/darwin/libjnidispatch.jnilib
com/sun/jna/linux-i386/libjnidispatch.so
com/sun/jna/sunos-x86/libjnidispatch.so
com/sun/jna/sunos-amd64/libjnidispatch.so
com/sun/jna/sunos-sparc/libjnidispatch.so
com/sun/jna/sunos-sparcv9/libjnidispatch.so
Then maybe you need to restart your IDE and that should work.
Related
I'm trying to use OpenCv 4 on Xamarin.Android by Java Binding Template. These are the steps that i've done:
0) I've compiled opencv binaries through cmake and mingw64 to get .jar and .a
I've put the .jar and the static libraries (.a) in Jars forlder of Xamarin Java Binding Template and i've compiled the template.
1.a) .jar Build Action is EmbeddedJar
1.b) libs Build Action is EmbeddedNativeLibrary
I've added a reference to that template in my Xamarin.Android project: the opencv methods were recognized correctly!
But, when i try to execute:
Mat Source = Imgcodecs.Imread(ImagePath, Imgcodecs.ImreadGrayscale);
i get an error:
Java.Lang.UnsatisfiedLinkError: 'No implementation found for long org.opencv.imgcodecs.Imgcodecs.imread_0(java.lang.String, int) (tried Java_org_opencv_imgcodecs_Imgcodecs_imread_10 and Java_org_opencv_imgcodecs_Imgcodecs_imread_10__Ljava_lang_String_2I)'
I think that there could be a missmatch of method name, maybe due to a wrong java parsing.
I've also tried to use shared libries (.so) by loading them through JavaSystem.LoadLibrary("LibraryNameWithoutInitialLib"), but i have the same error :/
Do you know why?
You cannot link static libraries with Xamarin.Android as the Xamarin/Mono NDK-based runtime is a static main entry executable and does not dynamically get built per project. If you do not need to use a .jar/.aar high-level wrapper, then you will need to use runtime shared libraries and define DllImportAttribute entries for the exported functions that you need to call.
Xamarin.Android supports the use of native libraries via the standard PInvoke mechanism.
Using Native Libraries
Use C/C++ libraries with Xamarin
Note: There are numerous OpenCV C# wrappers / DllImport files in open source ( i.e. a github search away 😁)
Note: If you are using a 3rd-party .jar/.aar , make sure that they are using OpenCV shared libraries and thus not requiring a gradle script to link them into an NDK-based Android app.
I've just followed exactly what was said in this tutorial and ran the command
/usr/local/google_appengine/endpointscfg.py get_client_lib java -bs gradle helloworld_api.NewsApi
I know my NewsApi service works, I've tested it on the Google APIs explorer.
I get a success message: API client library written to ./getNews-v1.zip
I extracted the zip and found the following files inside the folder (getNews):
No JAR file exists!! What do I use to set up the library in my Android client?
Any ideas? Thanks!
If you want a sources JAR and included dependencies to include in your project use '-bs default' or simply omit that option. Using '-bs gradle' or '-bs maven' assumes you are going to use one of those build tools to build a classes JAR yourself. The 'endpointscfg.py' of course won't compile sources to class files for you as it doesn't have knowledge of any Java environment.
More info in the docs:
https://cloud.google.com/appengine/docs/python/endpoints/endpoints_tool
I'm trying to integrate this specific library to my Android project, and the library is written in C/C++. I've miraculously gotten ndk-build to give me the needed .so file.
However, looking at it, there's a sample in the project, and they use a mysterious .jar with the API bindings of the .c/c++ files.
How do i either
create this special .jar file that has the API, based on the .so?
OR
directly add a method to the main c++ file and then call it from Java?
I've tried to re-wrap things using JNI, but it definitely doesn't seem to work. i keep getting UnsatisfiedLinkError.
A lot of the documentation online uses jni as the tutorial. i'm happy with just a few links to tutorials on JNA.
JNA provides a stub native library, libjnidispatch.so for a variety of platforms. You can build this library yourself, or extract one of the pre-built binaries from the project's lib/native/<platform>.jar packages.
You include libjnidispatch.so in your Android project the way you would any other JNI library. This is required; you cannot rely on JNA to dynamically unpack and use its native library automatically like on other platforms. The JNA project includes details for doing so (as well as instructions for building libjnidispatch.so yourself).
You then use jna.jar as you would any other Java jar file, and write your own (Java) mappings to match the native library you're trying to access. There's also a jna-min.jar which omits all the native platform libraries that are normally bundled in jna.jar.
Do go to project properties and build paths and remove JNA 4.0 and related classes.
This will work!
I am new in android. I see a lot of android libraries out there like github.com but when I download them none of them are a *.jar file like this one:
NumberProgressBar
It seems that all these libraries are for android studio NOT eclipse (Am I correct? This is important).
My question is: How do I use these libraries in eclipse?
I tried to import the downloaded library as an android project and then mark it as "is library" and then add to my project, but that did not work.
That library is designed to be built with Gradle for Android (with or without Android Studio), producing an AAR.
Eclipse does not have native AAR support. I have published a recipe and a Ruby script to convert an AAR into a library project that Eclipse can use, though I have not tested it much.
Or, you can download the source code and attempt to reorganize it into an Eclipse-style library project.
I just downloaded it and add it as library project and everything looks fine. How do you do it, it's extremely simple. Let us know in which step you have a problem so we can figure out what is wrong.
You have to build the library first.
For your example, read the Readme file, section 'Build'.
I am trying to make a project to read pdf in android phone.
So, I created the normal Android Project and installed the android-ndk-r6-windows.
And I built the 'libmibookreader.so' and set the native functions in my java class.
But after compiling my project I have a serious Error.
Caused by: java.lang.UnsatisfiedLinkError: Library mibookreader not found
Why this error caused?
I really don't know. I referenced the address of "http://flytgr.thoth.kr/blog/697421".
I followed down as the reference document described.
This is because your library was not loaded by the kernel. Are you sure that you placed your library inside the libs/armeabi/ folder of your project?
Check the logcat when you deploy your application, you should see some messages there that your library was loaded.
If you don't you could also try to use System.loadLibrary(libPath); to manually load your library.