- Home /
Using Java libraries in Unity C# project through IKVM.net: msvcrt dll-not-found
Hello guys,
I'm trying to access my java libraries in a Unity C# project but Unity keeps throwing dll-not-found errors. I'm on Unity Pro 3.5.7 and Mac OS X 10.8.4.
I'm using IKVM to convert java bytecode into .net dll and putting references to those in my Unity project, like the post here, http://forum.unity3d.com/threads/494...e-inside-Unity.
First, I encountered the problem of MonoPosixHelper.dll not found error, which is stated here, http://forum.unity3d.com/threads/999...lper-not-found. According to Unity's dll map, which can be accessed here on a mac, /Applications/Unity/Unity.app/Contents/Frameworks/Mono/etc/mono/config, I found out that MonoPosixHelper.dll actually means libMonoPosixHelper.dylib, and the problem no longer exists after I made a copy of it into my Unity project folder.
However, another problem appears after this one: DllNotFoundException: msvcrt. According to the same dll map I can see it's actually looking for libc.dylib, so I made a copy of that too, but it doesn't work this time. I tried copying it into my project folder, Assets sub folder, scripts sub folder and /Applications/Unity/Unity.app/Contents/Frameworks/Mono/lib folder but none of those worked.
My java library runs well with a standalone Xamarin Studio C# project so I believe it's something weird Unity did with its Mono library.
Does anyone have the same problem or has any ideas on where Unity actually looks for native dlls? (I think libMonoHelper.dylib is native too because it appeared in the library folder of Unity app's content folder, and that makes me wonder why Unity does not recognize that library in the first place)
Here is a copy of my error message.
DllNotFoundException: msvcrt
Mono.Unix.Native.Syscall.CopyUtsname (Mono.Unix.Native.Utsname& to, Mono.Unix.Native._Utsname& from)
Mono.Unix.Native.Syscall.uname (Mono.Unix.Native.Utsname& buf)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters)
ikvm.internal.MonoUtils.unameProperty (System.String )
ikvm.internal.Util..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for ikvm.internal.Util
java.lang.VMSystemProperties.getLibraryPath ()
java.lang.VMSystemProperties.initCommonProperties (java.util.Properties )
java.lang.VMSystemProperties.initProperties (java.util.Properties )
java.lang.Props..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for java.lang.Props
java.lang.System.lineSeparator ()
sun.misc.VM..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for sun.misc.VM
java.nio.Bits..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for java.nio.Bits
java.nio.ByteBuffer..ctor (Int32 , Int32 , Int32 , Int32 , System.Byte[] , Int32 )
java.nio.HeapByteBuffer..ctor (Int32 , Int32 )
java.nio.ByteBuffer.allocate (Int32 capacity)
net.named_data.jndn.util.Blob..ctor (System.Int32[] value)
TestEncodeDecodeInterest.Test () (at Assets/Scripts/init.cs:81)
init.Start () (at Assets/Scripts/init.cs:128)
========================================
Answer by Zhehao Wang · Feb 24, 2014 at 10:45 PM
Okay, for those who may be trying the same thing: Problem's fixed for OSX 10.8.4 and Unity 4.3.4.
After spending days trying everything I know regarding DllNotFound exceptions, we tried a newer version of Unity(4.3.4) and it simply worked. Whatever Unity's done with itself, it solved this problem at least. (One noticeable thing: Unity 4.3.4 and 3.5.7 are both using mono 2.6.5, which means it's not an upgrade of mono that fixed the problem) (There were errors, java.util.Date and GregorianCalendar at first)
Further note for users looking to use Java code. IKVM dlls references System.Drawing, which is not allowed by Unity. So IKVM runs in Unity, but Unity won't allow you to build. There are methods discussed in other threads to get around this restriction, but it seems that those methods can cause Unity/MonoDevelop to crash(at least in my case).
So, the best way would probably be using ILOG.J2CsMapping project, to translate Java code into C# code directly. Though the mapping dll, ILOG.J2CsMapping.dll references System.Web( and System.Drawing), It seems rather easy to make the translated code ILOG-free. It's better than rewriting everything in C#, at least, unless you need functionalities in System.Drawing. This method is tested with both 4.3.4 and 3.5.7 pro on Mac OS X 10.8.4.
Answer by AM_1 · May 31, 2014 at 12:56 PM
Not sure if this will work for you but look at this thread: http://forum.unity3d.com/threads/101097-Building-project-with-IKVM-dlls-inside
The last post says to go to "Edit -> Project Settings -> Player" and then under "Other settings for PC / Mac change the API Compatibility Level from '.NET 2.0 Subset' to '.NET 2.0'" This should let IKVM reference System.Drawing
.
Hope this helps (I know that this is sort of an old question, but I wont to help future readers.)
Your answer
Follow this Question
Related Questions
Can I access Java code from Unity? 2 Answers
Use KryoNet in C# via IKVM 0 Answers
Error when extending IKVM class in C# script 0 Answers
How to remove an add? 0 Answers
Touch menu for android 1 Answer