JNI method from static lib in ios?

Bob Vandette bob.vandette at oracle.com
Thu Mar 24 12:00:50 UTC 2016


The JNI specification was updated in SE 8 to support static JNI libraries.

The key change is around the JNI_OnLoad function.  

In order for Java to know that a JNI static library is bound to the current executable, 
you must have a unique JNI_OnLoad_{library} entry point that includes the name of the library.

Add a JNI_OnLoad_JavaToUIOasteboard entry point to your library when it’s built as a static
library.  This will allow the ClassLoader to successfully register it as a JNI library when System.loadLibrary
is called.  Take a look at the SE 8 JNI spec and the JDK9 JDK sources for other examples of these static library 
entry points.

Bob.


> On Mar 24, 2016, at 5:50 AM, Grigory Ptashko <grigory.ptashko at gmail.com> wrote:
> 
> Hello.
> 
> I'm able to launch jdk9 on ios both on the simulator and device.
> And also I've managed to remote debug java running in the simulator.
> 
> I want to use the JNI method from my java class.
> I made a static library libJavaToUIPasteboard.a.
> 
> I made it a fat library:
> 
> Here’s what lipo -info libJavaToUIPasteboard.a outputs:
> 
> Architectures in the fat file: libJavaToUIPasteboard.a are: armv7 i386 x86_64 arm64 
> 
> 
> Here's what nm libJavaToUIPasteboard.a outputs:
> 
> 0000000000000000 T _Java_EvalJava_stringToUIPasteboard
>                 U _NSLog
> 0000000000009b20 S _OBJC_CLASS_$_JavaToUIPasteboard
>                 U _OBJC_CLASS_$_NSObject
> 0000000000009af8 S _OBJC_METACLASS_$_JavaToUIPasteboard
>                 U _OBJC_METACLASS_$_NSObject
>                 U ___CFConstantStringClassReference
>                 U __objc_empty_cache
> 0000000000009ab0 s l_OBJC_CLASS_RO_$_JavaToUIPasteboard
> 0000000000009a68 s l_OBJC_METACLASS_RO_$_JavaToUIPasteboard
> 
> Just copying this file to app wrapper folder and also specifying the
> java.library.path gives java.lang.UnsatisfiedLinkError: no JavaToUIPasteboard in java.library.path.
> I tried both System.loadLibrary("JavaToUIPasteboard") and System.loadLibrary("libJavaToUIPasteboard").
> They both produce UnsatisfiedLinkError.
> 
> I'm a bit confused. How can I use this static lib from my class via JNI.
> 
> Thank you.
> 
> --
> Best regards,
> Grigory Ptashko
> 
> +7 (916) 1489766
> grigory.ptashko at gmail.com
> facebook.com/GrigoryPtashko
> 



More information about the mobile-dev mailing list