c# – Xamarin.Android JmDNS绑定问题

前端之家收集整理的这篇文章主要介绍了c# – Xamarin.Android JmDNS绑定问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我开始研究Xamarin. Android的JmDNS绑定.我设法获得了构建的绑定,但我无法从我的代码中引用它. https://github.com/ytn3rd/monodroid-bindings/tree/master/JmDNS

我遇到的第一个问题是没有IDNSListener类可供参考.所以我在那里添加了一个部分界面.我有它需要的函数void updateRecord(DNSCache dnsCache,现在很久,DNSEntry记录);注释掉,因为它会抱怨无法引用DNSCache或DNSEntry. (我相信我删除了DNSCache,这就是为什么)

不确定我做的一些事情是不是很糟糕,只是删除节点以使其编译.对于instnace.
添加了这个以删除以下错误.

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 interface member ‘Java.Util.IMapEntry.Key’.
‘Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry.Key’ cannot implement
‘Java.Util.IMapEntry.Key’ because it does not have the matching 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’ does not
implement interface member ‘Java.Util.IMapEntry.Value’.
‘Javax.Jmdns.Impl.JmDNSImpl.SubTypeEntry.Value’ cannot implement
‘Java.Util.IMapEntry.Value’ because it does not have the matching
return type of ‘Java.Lang.Object’. (CS0738) (JmDNS-Bindings)

问题来自Java.Util.IMapEntry类.我认为正确的操作是创建我自己的parital SubEntryType然后覆盖字符串Key属性但它不会捡起它.我的下一次尝试就是这样做.

Java.Lang.Object

哪个会解决错误,但会导致错误

E:\Users\brads_000\Documents\GitHub\ytn3rd\monodroid-bindings\JmDNS\bindings\obj\Debug\generated\src\Javax.Jmdns.Impl.JmDNSImpl.cs(12,12):
Error CS1502: The best overloaded method match 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,JniHandleOwnership.DoNotTransfer);
            return JNIEnv.NewString(__this.Key.ToString());
        }
    }
}

但同样,它不想选择这种新方法.

删除了javax.jmdns.impl.DNSCache因为与上面的键/值相同的错误,

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()’: return type must
be ‘System.Collections.ICollection’ to match overridden member
‘Java.Util.AbstractMap.EntrySet()’ (CS0508) (JmDNS-Bindings)

我似乎已经解决了这个问题

System.Collections.ICollection

即使它已经回归了.
public override global :: System.Collections.Generic.ICollection EntrySet()

无论如何,任何帮助将不胜感激,以获得这个真棒库和运行:)

解决方法

我能够正确地构建它的绑定项目.要正确建立它,请尝试使用以下方法.

1.从jmdns-3.4.1源代码重建jar文件.使DNSListener接口公开.删除测试包.然后导出源以获取更新的jar文件.

2.更新从步骤1创建的jar文件.确保将构建操作更新为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.在您的示例应用程序中,您必须再添加一个权限android.permission.ACCESS_WIFI_STATE.

5.此外,所有网络操作都应该从后台线程执行,并在主线程中通知UI.因此,相应地更新您的MainActivity类.

希望这可以帮助您正确地创建构建.示例代码的工作副本在此处上载https://github.com/Hitangshu/JmDNS_Xamarin_Library

原文链接:https://www.f2er.com/csharp/99503.html

猜你在找的C#相关文章