Xamarin.Android JmDNS binding problems

I started work on JmDNS bindings for Xamarin.Android. I managed to get the binding for the assembly, but I can not reference it from my code. https://github.com/ytn3rd/monodroid-bindings/tree/master/JmDNS

The first release I had was not for the IDNSListener class. Therefore, I added a partial interface there. I have a function for which it is needed void updateRecord (DNSCache dnsCache, for a long time, DNSEntry record); commented as he would complain about not being able to reference DNSCache or DNSEntry. (I believe that I deleted DNSCache and this is why)

Not sure if some of the things I did were bad, just deleting the nodes so that they could be compiled. For instnace. I added this to remove the following errors.

E: \ Users \ brads_000 \ Documents \ GitHub \ ytn3rd \ monodroid bindings \ JmDNS \ bindings \ OBJ \ Debug \ generated \ SRC \ Javax.Jmdns.Impl.JmDNSImpl.cs (24,24): Error CS0738: "Javax. Jmdns.Impl.JmDNSImpl.SubTypeEntry "does not implement the interface element" Java.Util.IMapEntry.Key ". 'Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry.Key' cannot implement "Java.Util.IMapEntry.Key" because it does not have a corresponding return type of "Java.Lang.Object". (CS0738) (JmDNS bindings) E: \ Users \ brads_000 \ Documents \ GitHub \ ytn3rd \ monodroid bindings \ JmDNS \ bindings \ OBJ \ Debug \ generated \ SRC \ Javax.Jmdns.Impl.JmDNSImpl.cs (24,24 ): Error CS0738: "Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry" did not implement the interface element "Java.Util.IMapEntry.Value". 'Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry.Value' cannot implement 'Java.Util.IMapEntry.Value' because it does not have the corresponding return type 'Java.Lang.Object'. (CS0738) (JmDNS bindings)

The problem is from the Java.Util.IMapEntry class. I thought that the correct action would be to create my own parit SubEntryType and then override the Key property of the Key, but it will not pick it up. My next attempt was to do this.

java.lang.Object

Which will resolve this error but then throw an error with

E: \ Users \ brads_000 \ Documents \ GitHub \ ytn3rd \ monodroid bindings \ JmDNS \ bindings \ OBJ \ Debug \ generated \ SRC \ Javax.Jmdns.Impl.JmDNSImpl.cs (12,12): Error CS1502: best overloaded method for 'Android.Runtime.JNIEnv.NewString (string)' has some invalid arguments (CS1502) (JmDNS bindings)

static IntPtr n_GetKey (IntPtr jnienv, IntPtr native__this) { global::Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry __this = global::Java.Lang.Object.GetObject<global::Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); return JNIEnv.NewString (__this.Key); } namespace Javax.Jmdns.Impl { public partial class SubTypeEntry { static IntPtr n_GetKey (IntPtr jnienv, IntPtr native__this) { global::Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry __this = global::Java.Lang.Object.GetObject<global::Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry> (jnienv, native__this, JniHandleOwnership.DoNotTransfer); return JNIEnv.NewString(__this.Key.ToString()); } } } 

But then again, he does not want to choose this new method.

I deleted javax.jmdns.impl.DNSCache due to the same errors with Key / Value as above, and

E: \ Users \ brads_000 \ Documents \ GitHub \ ytn3rd \ monodroid bindings \ JmDNS \ bindings \ OBJ \ Debug \ generated \ SRC \ Javax.Jmdns.Impl.DNSCache.cs (95.95): Error CS0508: 'Javax. Jmdns.Impl.DNSCache.EntrySet () ': the return type must be' System.Collections.ICollection 'to match the overridden member' Java.Util.AbstractMap.EntrySet () '(CS0508) (JmDNS-Bindings)

What I apparently fixed with

System.Collections.ICollection

Despite the fact that he has already returned.
public override global :: System.Collections.Generic.ICollection EntrySet ()

Anyway, any help would be appreciated to run this awesome library :)

+7
android c # xamarin xamarin.android jmdns
source share
2 answers

I was able to build the binding project correctly. To build it correctly, try the following approach.

1. Create a jar file from jmdns-3.4.1 source. Make the DNSListener interface public. Remove the test packages. Then export the source to get the updated jar file.

2. Install the jar file created from step 1. Be sure to update the build action to EmbededJar.

3.EnumMethods.xml

 <enum-method-mappings> <mapping jni-class="javax/jmdns/impl/DNSCache"> <method jni-name="entrySet" parameter="return" clr-enum-type="System.Collections.ICollection" /> </mapping> <mapping jni-class="javax/jmdns/impl/DNSCache._CacheEntry"> <method jni-name="getKey" parameter="return" clr-enum-type="Java.Lang.Object" /> </mapping> <mapping jni-class="javax/jmdns/impl/DNSCache._CacheEntry"> <method jni-name="getValue" parameter="return" clr-enum-type="Java.Lang.Object" /> </mapping> <mapping jni-class="javax/jmdns/impl/JmDNSImpl.ServiceTypeEntry.SubTypeEntry"> <method jni-name="getKey" parameter="return" clr-enum-type="Java.Lang.Object" /> </mapping> <mapping jni-class="javax/jmdns/impl/JmDNSImpl.ServiceTypeEntry.SubTypeEntry"> <method jni-name="getValue" parameter="return" clr-enum-type="Java.Lang.Object" /> </mapping> <mapping jni-class="javax/jmdns/impl/JmDNSImpl.ServiceTypeEntry"> <method jni-name="entrySet" parameter="return" clr-enum-type="System.Collections.ICollection" /> </mapping> </enum-method-mappings> 

4. In your sample application, you need to add another permission as the file android.permission.ACCESS_WIFI_STATE.

5. Also, the entire network operation should be performed from the background thread and notify the user interface in the main thread. Therefore, update your MainActivity class accordingly.

Hope this helps you build the assembly correctly. A working copy of the sample code is downloaded here https://github.com/Hitangshu/JmDNS_Xamarin_Library

+2
source share

Sometimes, when I have difficulty linking some libraries, I create a wrapper in java and link this new library to Xamarin.

I did this with a Unity project that was exported to Java. Unity has a library called UnityPlayer, and it cannot (I think it's impossible) link in Xamarin. So I created another library in java to call the methods I need and returns with return types.

You just need to place the dependency libraries in the right place. But you can LogCat get some help.

I hope you can make some progress.

+1
source share

All Articles