javaandroidjnananomsg

Want to implement nanomsg in android using its java binding jnanomsg getting java.lang.ExceptionInInitializerError


I am trying to implement nanomsg in android and i got java bindings from this link : http://niwinz.github.io/jnanomsg/ after this dependency
compile 'jnanomsg:jnanomsg:0.4.3' . It was returning me this sun/jna/libjnidispatch.so was not found.

After some time i figured out ".so" file which is required for jna is missing later i got all required ".so" from this link

https://github.com/java-native-access/jna/tree/master/dist after that i copied libjnidispatch.so file to app/src/main/jniLibs/armeabi-v7a/libjnidispatch.so and

i loaded the so file by System.loadLibrary("jnidispatch") after that app application got compiled. When i try create a object for ReqSocket sock = new ReqSocket(); I am getting following error:

java.lang.ExceptionInInitializerError
                  at nanomsg.Nanomsg.getSymbols(Nanomsg.java:35)
                  at nanomsg.Nanomsg.<clinit>(Nanomsg.java:48)
                  at nanomsg.Nanomsg$constants.<clinit>(Nanomsg.java:51)
                  at nanomsg.reqrep.ReqSocket.<init>(ReqSocket.java:13)
                  at com.example.nanomsg.onClick(MainActivity.java:125)
                  at android.view.View.performClick(View.java:5201)
                  at android.view.View$PerformClick.run(View.java:21163)
                  at android.os.Handler.handleCallback(Handler.java:746)
                  at android.os.Handler.dispatchMessage(Handler.java:95)
                  at android.os.Looper.loop(Looper.java:148)
                  at android.app.ActivityThread.main(ActivityThread.java:5443)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
                  Caused by: java.lang.IllegalStateException: The SecurityManager implementation on this platform is broken; you must explicitly provide the class to register
                  at com.sun.jna.Native.getCallingClass(Native.java:1295)
                  at com.sun.jna.Native.register(Native.java:1252)
                  at nanomsg.NativeLibrary.<clinit>(NativeLibrary.java:30)
                  at nanomsg.Nanomsg.getSymbols(Nanomsg.java:35) 
                  at nanomsg.Nanomsg.<clinit>(Nanomsg.java:48) 
                  at nanomsg.Nanomsg$constants.<clinit>(Nanomsg.java:51) 
                  at nanomsg.reqrep.ReqSocket.<init>(ReqSocket.java:13) 
                  at com.example.nanomsg.MainActivity.onClick(MainActivity.java:125) 
                  at android.view.View.performClick(View.java:5201) 
                  at android.view.View$PerformClick.run(View.java:21163) 
                  at android.os.Handler.handleCallback(Handler.java:746) 
                  at android.os.Handler.dispatchMessage(Handler.java:95) 
                  at android.os.Looper.loop(Looper.java:148) 
                  at android.app.ActivityThread.main(ActivityThread.java:5443) 
                  at java.lang.reflect.Method.invoke(Native Method) 
                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)

at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 

Could anyone can please help me what mistake i am doing here. Any help would be appreciated.


Solution

  • It looks like the problem is that Native.register() without a class argument requires a context class loader which can successfully report the calling class. Android does not provide one.

    Without that, Native.register() requires you to explicitly identify the class you want to register. Unfortunately, it may be impossible to even load the class defined by nanomsg if their register is in a static block. You would need to copy their class definition (which may be small or large) and register your own mapping. Or ask them to patch their register call to work with Android.

    See also jna-users mailing list.