dotnet / java-interop

Java.Interop provides open-source bindings of Java's Java Native Interface (JNI) for use with .NET managed languages such as C#
Other
189 stars 48 forks source link

duplicate definition of delegate #1210

Closed ljzj2 closed 3 months ago

ljzj2 commented 3 months ago
        static Delegate? cb_getSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_;
#pragma warning disable 0169
        static Delegate GetGetSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_Handler ()
        {
            if (cb_getSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_ == null)
                cb_getSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_ = JNINativeWrapper.CreateDelegate (new _JniMarshal_PPLL_V (n_GetSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_));
            return cb_getSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_;
        }

CS0102 RCSPController has already contain definition of cb_getSoundCardEqInfo_Landroid_bluetooth_BluetoothDevice_Lcom_jieli_bluetooth_interfaces_rcsp_callback_OnRcspActionCallback_

yes it is contained and I specified the eventName or managedName it is not work.

jpobst commented 3 months ago

You will likely need to follow this guide available from here.

jpobst commented 3 months ago

Please post the entire .cs file that contains the issue, as well as any metadata you are using.

ljzj2 commented 3 months ago

This is the .cs file Com.Jieli.Bluetooth.Impl.Rcsp.RCSPController.zip

this is the metadata.xml:

<metadata>
    <attr path="/api/package[@name='com.jieli.bluetooth.interfaces.bluetooth']/interface[@name='OnBrEdrListener']/method[@name='onA2dpStatus']" name="argsType">A2dpStatusEventArgs1</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.interfaces.bluetooth']/interface[@name='OnBtDevicePairListener']/method[@name='onAdapterStatus']" name="argsType">AdapterStatusEventArgs1</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.interfaces.bluetooth']/interface[@name='OnBrEdrListener']/method[@name='onHfpStatus']" name="argsType">HfpStatus1</attr>

    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothBle']/method[@name='addListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothBle']/method[@name='removeListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothBrEdr']/method[@name='addListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothBrEdr']/method[@name='removeListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothDiscovery']/method[@name='addListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothDiscovery']/method[@name='removeListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothPair']/method[@name='addListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothPair']/method[@name='removeListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothSpp']/method[@name='addListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl']/class[@name='BluetoothSpp']/method[@name='removeListener']/parameter[1]" name="managedType">Java.Lang.Object</attr>

    <attr path="/api/package[@name='com.jieli.bluetooth.constant']/class[@name='GattError']/field[@name='GATT_ERROR']" name="managedName">GattError1</attr>

    <attr path="/api/package[@name='com.jieli.bluetooth.impl.rcsp']/class[@name='RCSPController']/method[@name='getSoundCardEqInfo' and count(parameter)=2 and parameter[1][@type='android.bluetooth.BluetoothDevice'] and parameter[2][@type='com.jieli.bluetooth.interfaces.rcsp.callback.OnRcspActionCallback']]" name="managedName">GetSoundCardEqInfo1</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl.rcsp']/class[@name='RCSPController']/method[@name='updateFunctionValue' and count(parameter)=4 and parameter[1][@type='android.bluetooth.BluetoothDevice'] and parameter[2][@type='int'] and parameter[3][@type='byte'] and parameter[4][@type='com.jieli.bluetooth.interfaces.rcsp.callback.OnRcspActionCallback']]" name="managedName">UpdateFunctionValue1</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl.rcsp']/class[@name='RCSPController']/method[@name='getSoundCardStatusInfo' and count(parameter)=2 and parameter[1][@type='android.bluetooth.BluetoothDevice']]" name="managedName">GetSoundCardStatusInfo1</attr>
    <attr path="/api/package[@name='com.jieli.bluetooth.impl.rcsp']/class[@name='RCSPController']/method[@name='setSoundCardEqInfo' and count(parameter)=3 and parameter[1][@type='android.bluetooth.BluetoothDevice'] and parameter[2][@type='byte[]']]" name="managedName">SetSoundCardStatusInfo1</attr>

    <attr path="/api/package[@name='com.jieli.bluetooth.impl.rcsp']/class[@name='RCSPController']/method[@name='getSoundCardEqInfo' and count(parameter)=2 and parameter[1][@type='android.bluetooth.BluetoothDevice'] and parameter[2][@type='com.jieli.bluetooth.interfaces.rcsp.callback.OnRcspActionCallback']]" name="eventName"></attr>
</metadata>
jpobst commented 3 months ago

It looks like the original Java has something where 2 methods have the same signature except one has a generic parameter:

public class RCSPController {
  getSoundCardEqInfo (android.bluetooth.BluetoothDevice, com.jieli.bluetooth.interfaces.rcsp.callback.OnRcspActionCallback) { ... }
  getSoundCardEqInfo (android.bluetooth.BluetoothDevice, com.jieli.bluetooth.interfaces.rcsp.callback.OnRcspActionCallback<java.lang.Boolean>) { ... }
}

However, since Java generics get erased, we end up with the same method in C#:

public virtual unsafe void GetSoundCardEqInfo (global::Android.Bluetooth.BluetoothDevice? p0, global::Com.Jieli.Bluetooth.Interfaces.Rcsp.Callback.IOnRcspActionCallback? p1)
public virtual unsafe void GetSoundCardEqInfo (global::Android.Bluetooth.BluetoothDevice? device, global::Com.Jieli.Bluetooth.Interfaces.Rcsp.Callback.IOnRcspActionCallback? @callback)

Because they have the same parameters and the delegate name is based on Java Name + Parameter Types, they end up with the same delegate name.

The easiest fix would be to remove one of the methods from the binding so there is no longer a duplicate delegate:

<remove-node path="/api/package[@name='com.jieli.bluetooth.impl.rcsp']/class[@name='RCSPController']/method[@name='getSoundCardEqInfo' and count(parameter)=2 and parameter[1][@type='android.bluetooth.BluetoothDevice'] and parameter[2][@type='com.jieli.bluetooth.interfaces.rcsp.callback.OnRcspActionCallback&lt;java.lang.Boolean&gt;']]" />
jpobst commented 3 months ago

Related: https://github.com/xamarin/java.interop/issues/1155