mono / Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
MIT License
758 stars 95 forks source link

Function ignored due to ignored param #755

Open AndyNetDuma opened 4 years ago

AndyNetDuma commented 4 years ago

I am trying to get callbacks working from C# to Android kotlin. I have the following classes.

    [Register("hello_from_csharp.Class1")]
    public class Class1
    {
        public int count = 0;

        [Export("aStringFunction")]
        public string aStringFunction()
        {
            return "Hello from C#";
        }

        [Export("startLoop")]
        public void StartLoop(JavaCallback callback)
        {
            Task.Run(() =>
            {
                while (true)
                {
                    callback.Callback(count++.ToString());
                    Thread.Sleep(500);
                }
            });
        }
    }
    [Register("hello_from_csharp.JavaCallback")]
    public abstract class JavaCallback : Java.Lang.Object
    {
        public JavaCallback() { }

        public JavaCallback(IntPtr handle, JniHandleOwnership transfer) : base(handle, transfer) { }

        [Export("Callback")]
        public abstract void Callback(string data);
    }

I have successfully created Class1 and called aStringFunction from kotlin. However StartLoop never makes it into the library. Looking at the build logs it says 'StartLoop' was ignored due to ignored param Also worth noting, I was able to create the an instance of JavaCallback with the overload so JavaCallback itself makes it in.

        var j = object : JavaCallback()
        {
            override fun Callback(p0: String?) {
                someText.text = p0;
            }
        }

I have been following this guide from Microsoft however it was written in 2017 so maybe things have changed since.

So in short why is StartLoop being removed and is there a better way to implement callbacks now?

If it helps I have attached a full build log. buildLog.txt

AndyNetDuma commented 4 years ago

Is there a workaround I can use while waiting for this to be fixed?