Xamarin Android Markwon 库的绑定

Xamarin Android Bindings For Markwon Library

我正在尝试为库生成 Xamarin 绑定:

https://github.com/noties/Markwon

https://repo1.maven.org/maven2/io/noties/markwon/core/4.6.1/core-4.6.1.aar

我还没有修改 metadata.xml 或任何东西。我已将 aar 添加为 LibraryProjectZip,但在尝试编译它时遇到问题。

0>obj/Debug/generated/src/IO.Noties.Markwon.SpannableBuilder.cs(10,68): Error CS0738 : 'SpannableBuilder' does not implement interface member 'IAppendable.Append(char)'. 'SpannableBuilder.Append(char)' cannot implement 'IAppendable.Append(char)' because it does not have the matching return type of 'IAppendable'.

0>obj/Debug/generated/src/IO.Noties.Markwon.SpannableBuilder.cs(10,68): Error CS0738 : 'SpannableBuilder' does not implement interface member 'IAppendable.Append(ICharSequence?)'. 'SpannableBuilder.Append(ICharSequence)' cannot implement 'IAppendable.Append(ICharSequence?)' because it does not have the matching return type of 'IAppendable'.

0>obj/Debug/generated/src/IO.Noties.Markwon.SpannableBuilder.cs(10,68): Error CS0738 : 'SpannableBuilder' does not implement interface member 'IAppendable.Append(ICharSequence?, int, int)'. 'SpannableBuilder.Append(ICharSequence, int, int)' cannot implement 'IAppendable.Append(ICharSequence?, int, int)' because it does not have the matching return type of 'IAppendable'.

0>obj/Debug/generated/src/IO.Noties.Markwon.Utils.NoCopySpannableFactory.cs(56,79): Warning CS0108 : 'NoCopySpannableFactory.Instance' hides inherited member 'SpannableFactory.Instance'. Use the new keyword if hiding was intended.

出于测试目的,如果我从 SpannableBuilder 的界面中删除 global::Java.Lang.IAppendable,我会走得更远,但它会在 Java 问题上中断:

1>obj/Debug/android/src/mono/io/noties/markwon/core/CorePlugin_OnTextAddedListenerImplementor.java(4,8): Error JAVAC0000 javac: error: CorePlugin_OnTextAddedListenerImplementor is not abstract and does not override abstract method onTextAdded(MarkwonVisitor,String,int) in OnTextAddedListener public class CorePlugin_OnTextAddedListenerImplementor

class 的生成代码在这里:

package mono.io.noties.markwon.core;


public class CorePlugin_OnTextAddedListenerImplementor
    extends java.lang.Object
    implements
        mono.android.IGCUserPeer,
        io.noties.markwon.core.CorePlugin.OnTextAddedListener
{
/** @hide */
    public static final String __md_methods;
    static {
        __md_methods = 
            "";
        mono.android.Runtime.register ("IO.Noties.Markwon.Core.CorePlugin+IOnTextAddedListenerImplementor, Markwon", CorePlugin_OnTextAddedListenerImplementor.class, __md_methods);
    }


    public CorePlugin_OnTextAddedListenerImplementor ()
    {
        super ();
        if (getClass () == CorePlugin_OnTextAddedListenerImplementor.class)
            mono.android.TypeManager.Activate ("IO.Noties.Markwon.Core.CorePlugin+IOnTextAddedListenerImplementor, Markwon", "", this, new java.lang.Object[] {  });
    }

    private java.util.ArrayList refList;
    public void monodroidAddReference (java.lang.Object obj)
    {
        if (refList == null)
            refList = new java.util.ArrayList ();
        refList.add (obj);
    }

    public void monodroidClearReferences ()
    {
        if (refList != null)
            refList.clear ();
    }
}

我根据这个 SO 回答采纳了建议:

并创建了一个简单的包装器来调用我需要的函数。我的包装器 .aar 文件添加为 LibraryProjectZip,然后将 markwon 库(及其依赖的 jar)添加为 EmbeddedReferenceJar.

它允许我 wrap/call 只使用我需要使用的函数,而无需为整个库创建绑定。