Search code examples
javac#xamarin.android

Xamarin Android Bindings For Markwon Library


I am trying to generate Xamarin bindings for the library:

https://github.com/noties/Markwon

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

I have not modified the metadata.xml or anything yet. I have added the aar as a LibraryProjectZip, but I get issues when trying to compile it.

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.

For testing purposes, if I delete the global::Java.Lang.IAppendable from the interfaces of SpannableBuilder I get further along, but it breaks on a Java issue:

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

The generated code for that class is here:

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 ();
    }
}

Solution

  • I took advice based on this SO answer: https://stackoverflow.com/a/24169499/14977771

    And created a simple wrapper to call the functions I needed. My wrapper .aar file was added as LibraryProjectZip and then added the markwon library (and its dependent jars) as EmbeddedReferenceJar.

    It allowed me to wrap/call only the functions I needed to use without creating bindings for the whole library.