1

I am working on porting a Java SDK to Xamarin.Android.

After solving numerous errors, I am stuck in this one:

/Users/alejandro_l/Projects/KontaktBeaconSDK/KontaktBeaconSDK/obj/Debug/generated/src/Com.Kontakt.Sdk.Android.Ble.Configuration.Scan.EddystoneScanContext.cs(65,65): Error CS1715: Com.Kontakt.Sdk.Android.Ble.Configuration.Scan.EddystoneScanContext.EventTypes': type must beSystem.Collections.Generic.ICollection' to match overridden member `Com.Kontakt.Sdk.Android.Ble.Configuration.Scan.AbstractProfileSpecificScanContext.EventTypes' (CS1715) (KontaktBeaconSDK)

For solving the error I though that it should be OK to use the following line in the metadata.xml telling the generator to change the type of the method to match with the abstract class:

<attr path="/api/package[@name='com.kontakt.sdk.android.ble.configuration.scan']/class[@name='EddystoneScanContext']/method[@name='getEventTypes' and count(parameter)=0]" name="managedType">System.Collections.Generic.ICollection</attr>

Based on: https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/customizing-bindings/java-bindings-metadata/#managedType

The generated output still has the wrong shape:

        static IntPtr id_getEventTypes;
    public override unsafe global::System.Collections.ICollection EventTypes {
        // Metadata.xml XPath method reference: path="/api/package[@name='com.kontakt.sdk.android.ble.configuration.scan']/class[@name='EddystoneScanContext']/method[@name='getEventTypes' and count(parameter)=0]"
        [Register ("getEventTypes", "()Ljava/util/Collection;", "GetGetEventTypesHandler")]
        get {
            if (id_getEventTypes == IntPtr.Zero)
                id_getEventTypes = JNIEnv.GetMethodID (class_ref, "getEventTypes", "()Ljava/util/Collection;");
            try {
                return global::Android.Runtime.JavaCollection.FromJniHandle (JNIEnv.CallObjectMethod  (Handle, id_getEventTypes), JniHandleOwnership.TransferLocalRef);
            } finally {
            }
        }
    }

As you can see System.Collections.ICollection is generated and not System.Collections.Generic.ICollection. Note: I even still did not figure it out how to also set the generic type, but that is the next step.

I am a newbie in binding and I cannot figure it out. Can someone tell me what I am doing wrong? Am I trying an impossible here? Do I need to change the source code of the SDK? (Notice that if I use "Build" and change manually the output I may get the dll in a future (still 49 errors left though) but I wonder if I can solve in a proper way).

Another useful link I used: https://gist.github.com/brendanzagaeski/9607158

1 Answer 1

1

Found it:

<attr path="/api/package[@name='com.kontakt.sdk.android.ble.configuration.scan']/class[@name='EddystoneScanContext']/method[@name='getEventTypes' and count(parameter)=0]" name="return">System.Collections.Generic.ICollection&lt;Com.Kontakt.Sdk.Android.Ble.Discovery.EventType&gt;</attr>

It seems the error has disappeared due to name="return". I do not know why return does not appear in the documentations but it appears in the api.xml so it should be OK.

2
  • Warning: From documentation "managedReturn" = "Changes the return type of a method. This does not change the return attribute (as changes to return attributes can result in incompatible changes to the JNI signature)". That is why it is avoided. I will check if I get further errors.
    – Alejandro
    Commented Jul 11, 2016 at 6:46
  • You are my hero. After 5h of searching this is only answer which gave good directions and almost answered my question. I needed insted generic IList property IList<SomeObject>. My solution <attr path="/api/package[@name='org.webrtc']/class[@name='MediaStream']/field[@name='audioTracks']" name="type">System.Collections.IList&lt;Org.Webrtc.AudioTrack&gt;</attr>
    – valentasm
    Commented Sep 3, 2020 at 17:37

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.