3

I'm trying to embed some jars from a native project into my Xamarin Android app, and I have hit two separate (but I suspect related) problems:

  1. One of the files in the package is jna-4.2.0.jar. When I try to build the binding project on its own, I get this error:

The type or namespace name 'ICallback' does not exist in the namespace 'Com.Sun.Jna' (are you missing an assembly reference?)

The generated code is as follows:

    [Register ("getCallback", "(Ljava/lang/Class;Lcom/sun/jna/Pointer;)Lcom/sun/jna/Callback;", "")]
    public static unsafe global::Com.Sun.Jna.ICallback GetCallback (global::Java.Lang.Class type, global::Com.Sun.Jna.Pointer p)
    {
        if (id_getCallback_Ljava_lang_Class_Lcom_sun_jna_Pointer_ == IntPtr.Zero)
            id_getCallback_Ljava_lang_Class_Lcom_sun_jna_Pointer_ = JNIEnv.GetStaticMethodID (class_ref, "getCallback", "(Ljava/lang/Class;Lcom/sun/jna/Pointer;)Lcom/sun/jna/Callback;");
        try {
            JValue* __args = stackalloc JValue [2];
            __args [0] = new JValue (type);
            __args [1] = new JValue (p);
            global::Com.Sun.Jna.ICallback __ret = global::Java.Lang.Object.GetObject<global::Com.Sun.Jna.ICallback> (JNIEnv.CallStaticObjectMethod  (class_ref, id_getCallback_Ljava_lang_Class_Lcom_sun_jna_Pointer_, __args), JniHandleOwnership.TransferLocalRef);
            return __ret;
        } finally {
        }
    }

I have also tried downloading the latest version, jna-4.4.0.jar, from https://github.com/java-native-access/jna, but that generates the same error.

  1. The library I'm using generates this error:

'Version' does not implement interface member 'IComparable.CompareTo(Object)'

I have tried to solve this issue, following the Xamarin documentation, and using the comments in the generated cs files, by adding this line to the metadata.xml file in my bindings project:

<attr path="/api/package[@name='com.innovatrics.iface']/class[@name='Version']/method[@name='compareTo' 
    and count(parameter)=1 
    and parameter[1][@type='com.innovatrics.iface.Version']]" 
    name="managedType">Java.Lang.Object</attr>

but this seems to have had no effect at all.

Rob Lyndon
  • 12,089
  • 5
  • 49
  • 74

2 Answers2

3

Have you try to change the classname in this case?

Try to add the following in the Metadata.xml file (untested):

<attr path="/api/package[@name='com.sun.jna']/interface[@name='Callback']" name="name">ICallback</attr>

This will change the interface name from Callback in Java to ICallback in C#

Pierre
  • 8,397
  • 4
  • 64
  • 80
0

Using the above rename method, i was able to get past this, but found a few more errors when also attempting to Bind the JNA Jar file.

I wanted to know, how much further you got with this, and if possible could share the Metadata.xml file that allowed you to complete this binding please ?

Jeffrey Holmes
  • 337
  • 3
  • 11