- Home /
Using JNI without Android?
Does Unity provide for any way to invoke JNI without having to do an Android build?
I'm in a situation where I want to use functionality from Java classes that are packaged inside JARs, but I want to target PC as well as other platforms. I tried using the AndroidJNI API that Unity provides, but I get the feeling that it (unsurprisingly) only works on Android. I also tried making a DLL using C++ JNI, but I haven't been able to get that to work properly from within Unity.
Does anyone have any ideas on what I could do here? Thanks much.
Answer by mikebelotti · Aug 02, 2016 at 08:41 PM
I've basically settled on using IKVM as a workaround--this supposedly compiles JARs to managed DLLs which can be consumed by Mono C#. I did a little test of this on PC and Android and got an example working, so I'll probably take this route.
This is the best solution in this case. You can't just run or use JARs in a PC build since a PC build doesn't use or have any Java runtime built-in. So Java bytecode can only be run by a proper Java V$$anonymous$$. Android uses a special Java V$$anonymous$$ for running apps. While I$$anonymous$$V$$anonymous$$ also provides a Java V$$anonymous$$ implemented in .NET / $$anonymous$$ono it's best for performance if you can simply crosscompile it to $$anonymous$$ono.