java and I have its own .so file, I made a new android project and I import the class.java and the so file under lib\armeabi\lib.so I tried to compile it but I got errors about can't find the library.
I did many searches and found to make a new so file. I have the header file and I gone to androidtools add native support and created empty cpp. I copied the header content to the cpp then in android.mk I matched the nessecary and then I compiled i am getting some errors
java.lang.UnsatisfiedLinkError: Couldn't load FXTEST from loader dalvik.system.PathClassLoader[dexPath=/data/app/com.example.fxtest-.apk,libraryPath=/data/app-lib/com.example.fxtest-2]: findLibrary returned null
I created jni_onload method and still got errors Any Idea? Let me know if you want some pictures, I will attach
I suppose you might try to provide Java with the path to you native library with the following java option:
-Djava.library.path=/Path/To/You/File
I am not an android developer though, so I might be wrong.
Related
I'm using the JNA's com.sun.jna.NativeLibrary class in order to load the VLCJ native library. I'm working on an armv8(aarch x64)-based linux device. Below is my code, note that i am using the latest JNA version jna-4.5.2:
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), Constants.DEPLIB_OUTPUT_DIRECTORY);
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
LibXUtil.initialise();
First i was getting this error:
java.lang.UnsatisfiedLinkError: JNA native support (com/sun/jna/linux-aarch64/libjnidispatch.so) not found in resource path
After a quick search i found that i must copy the jna native lib directory from inside the jar into the jvm lib path, where the jna jar library has pre-built libraries for almost all known systems as shown in the image below:
jna-4.5.2 internal content.jpeg
After doing that, the above exception disappeared but another one came up:
java.lang.UnsatisfiedLinkError: Can't obtain static method fromNative(Method, Object) from class com.sun.jna.Native
the exception is saying that it couldn't find the method fromNative(Method, Object) in the class com.sun.jna.Native however after decompiling this class i found that the method already exists.
I'm out of ideas know, any help would be highly appreiated, thanks!.
solve by:
undo this step:
After a quick search i found that i must copy the jna native lib
directory from inside the jar into the jvm lib path...
remove all jna modules (jars) from my project
download and link the following jars into my project:
jna.jar
jna-platform.jar
linux-aarch64.jar
If the jar files: jna-5.11.0.jar and jna-platform-5.11.0.jar (or whatever version number you are using) if in you lib path (build path in Eclipse), the java command option:
-Djna.nosys=true
may solve the problem. When first started, JNA is loads its own native access library and it wasn't finding it. jna.nosys=true allows JNA to look in the jna-X.XX.X.jar file for what it needs. The error message confused my because JNA seemed to be found and loaded, but it was complaining about not finding 'fromNative'.
From JNA documentation:
Loading JNA
JNA includes a small, platform-specific shared library which enables all
native access. When the Native class is first accessed, JNA will first
attempt to load this library from the directories specified in
jna.boot.library.path. If that fails and jna.nosys=false is set, it will
fall back to loading from the system library paths. Finally it will attempt
to extract the stub library from from the JNA jar file, and load it.
The jna.boot.library.path property is mainly to support jna.jar being
included in -Xbootclasspath, where java.library.path and LD_LIBRARY_PATH are
ignored. It is also useful for designating a version of the library to use
in preference to any which may already be installed on the system.
...
I want to convert a wav file into flac on Android platform using Unity3d Game Engine. So I downloaded the latest version of javaFlacEncoder and converted the .jar file into .dll using ikvmc.exe so I can use its functionality in a C# script. Then I put the DLL file into Plugins/Android folder. But it gives the following error:
Assets/Core.cs(70,3): error CS0012: The type 'java.lang.Object' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'IKVM.OpenJDK.Core, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58'
Corresponding line in Core.cs:
FLAC_FileEncoder flacEncoder = new FLAC_FileEncoder();
How can I fix it? If there is a way to use the .jar file directly, I'm also okay with that.
Fixed it by copying IKVM.OpenJDK.Core.dll to the same folder (Plugins/Android).
I have created a JNI library with visual studio to use in java application and internally this dll calls another DLL (openssl). Now when i load this library with eclipse I get an error saying "Can't find dependent libraries" unless I put the path of the other DLL on the PATH variable.
in thread "main" java.lang.UnsatisfiedLinkError: C:\*****\jniDLL.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1939)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1864)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1854)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at iwinAlgTest.test.<clinit>(test.java:7)
And I've already tried adding it to -Djava.library.path and to the classpath, and i also included all of my dll and openssl dll and lib files like libeay32.lib but neither worked. Is there a way to do this?
I tried to use Dependency Walker to check if there are any files required by my jniDLL.dll
but i get interesting thing:
what i really do to create my jniDLL:
(jniDLL --> calls myDLL.dll) ==> (myDLL.dll --> calls openssl library)
but Dependency Walker says that
(jniDLL --> depends on myDLL.exe) not myDLL.dll
Note : at first it was a win32 application( which output myDLL.exe) but i changed the project setting to output myDLL.dll then i create another project to create a JNI dll from myDLL.dll which i wrote in c++
One way to bypass this is to load your openssl.dll prior to loading myDLL, so myDLL will find the symbols loaded when it tries to initiate .
Other ways to go around this :
add the openssl.dll to PATH (you already mentioned this)
copy openssl in system32 at install time
put openssl in the same folder as your executable path
This however will only work on Windows.
In linux, you will have to change the rpath inside the .so (but I believe this is out of scope).
I'll try to illustrate the problem as simple as I can.
I have a JAR file, which I extracted using Winrar. (The jar file contains an open source android library).
I want to modify this JAR file by adding a new class to the library.
So here are my steps:
First, I created a class using Eclipse and set the package name same as the android's library package name.
Second, I copied this java File to the folder of the other java files in the library.
Third, I tried to compile the JAVA file via the CMD using javac.
The path of the new java file and the other .JAVA and .CLASS files of the library is: C:\com\example\core\
The name of the new java file would be: "MyNewClass.java"
The command I run via the CMD is: javac C:\com\example\core\MyNewClass.java
But, during the compilation I get many errors saying: Cannot find symbols.
I've been looking up for a solution of this problem but couldn't figure how to solve it and make the new JAR File having another class that I created seperately.
What am I missing?
As per earlier comments:
Rather than trying to modify the JAR, you can get access to the full source code of the Universal Image Loader library by cloning the repository using git or hitting "Download ZIP" on the righthand side of the page you linked.
Once you have the source, import the library in your IDE. From there on you'll be able to build the whole thing from scratch, make any adjustments/modifications you like, etc.
Your classpath might be wrong or there might be some mistake in package name.
When a Java program is being compiled the compiler it creates a list of all the identifiers in use. If it can't find what an identifier refers to it cannot complete the compilation. This is what the cannot find symbol error message is saying, it doesn't have enough information to piece together what the Java code wants to execute.
Try:
javac -cp com/* C:\com\example\core\MyNewClass.java
That should make the compiler aware of all the other classes under com/...
I have a dll file and I am trying to call functions of it through a Java program through JNA
But the problem is It is not able to locate my dll file and throwing the following exception:
java.lang.UnsatisfiedLinkError: Unable to load library 'UsbDll': The specified module could not be found.
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:163)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:236)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:199)
at com.sun.jna.Native.register(Native.java:1018)
at com.MainClass.<clinit>(MainClass.java:15)
Exception in thread "main"
Below is my program:
package com;
import com.sun.jna.Native
public class MainClass {
static {
Native.register("UsbDll");
}
public native int method();
public static void main(String[] args) {
}
}
The name of my dll file is UsbDll.dll and my operating system is Windows.
============================ EDITED ================================
The location of my dll file is "c:\UsbDll.dll"
When I placed another dll file at the same location, JNA has located it so I think that the problem is with my "UsbDll.dll" file only.
When I tried to load both the dll files (UsbDll.dll and the another dll) with the following command
System.load("c:\\UsbDll.dll");
System.load("c:\\another.dll");
It loaded the "another.dll" successfully but for "UsbDll.dll", it throws the following exception:
java.lang.UnsatisfiedLinkError: C:\UsbDll.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1699)
at java.lang.Runtime.load0(Runtime.java:770)
at java.lang.System.load(System.java:1003)
at com.MainClass.<clinit>(MainClass.java:16)
Exception in thread "main"
Q1. It looks like it is not finding some dependent libraries. But as I am totally new to these dlls, Is there anything I am missing or I need to ask the vendor to provide me the dependent libraries.
OR
Is it depends on some standard libraries which I can download from internet? If it is, then how to find the libraries name on which it depends?
============================ EDITED #2 ================================
I ran the Dependency Walker on my UsbDll.dll file to find the missing dependencies and found the following missing dependencies.
WER.DLL (referred by library WINNM.DLL found in my c:\windows\system32)
IESHIMS.DLL (referred by library WINNM.DLL found in my c:\windows\system32)
WDAPI920.DLL (referred directly by my UsbDll.dll)
Q1. As WINNM.DLL was found in my system32 folder, it seems as the standard dll. And if this standard dll is referring to 2 missing dlls (WER.DLL & IESHIMS.DLL), then I suspect how other applications are working who are using this WINNM.DLL file?
Q2. I googled for WDAPI920.dll (that was referred my UsbDll.dll directly) and many search results appeared with the same dll name. So it also looks like some standard library. So how to fix these dependencies? From where to download them? After downloading, Can I place them in the same directory in which my main dll (UsbDll.dll) is or I need to do something extra to load my dll (UsbDll.dll) sucessfully?
From your edited code it is quite evident that the UsbDll.dll depends on some standard modules which are not there on your system (for example if it uses ATL and if you have don't have proper runtime then it is guaranteed to fail). To resolve this you will need proper runtime environment.
Also it is possible that the dll in concern depends on some vendor specific module. For you the best option is (and fastest option would be) to contact the vendor. Otherwise, try to install proper runtime from the microsoft site (but its more of hit-and-trial)
Update
Use the below links for finding more about DLL dependency:
How do I determine the dependencies of a .NET application?
http://msdn.microsoft.com/en-us/library/ms235265.aspx
Command line tool to find Dll dependencies
Update 2
See the below mentioned link for the missing dll details (but it is specific to the windows version)
Dependency Walker reports IESHIMS.DLL and WER.DLL missing?
http://social.msdn.microsoft.com/Forums/en/vsx/thread/6bb7dcaf-6385-4d24-b2c3-ce7e3547e68b
From few simple google queries, WDAPIXXX.dll appears to be some win driver related thing (although i am not too sure). Check this link, they have something to say about WDAPI http://www.jungo.com/st/support/tech_docs/td131.html.
The DLL must by in the Path specified by LD_LIBRARY_PATH (see your env), or, in the case of JNA, in the current directory.