You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Default Instance Java Interface Methods are ignored by Binding Tools #7125
The binding tools seem to ignore default instance interface methods when generating the C# interface.
For example, for the following Java interface:
package com.example.calculator;
public interface Calculator {
default int Add(int a, int b) {
return a + b;
}
int Subtract(int a, int b);
}
This is the C# interface that is generated:
public interface ICalculator {
int Subtract(int a, int b);
}
Steps to Reproduce
Create a new file: Calculator.java
Paste the Java interface code written in the description into the file.
Open a terminal in the folder containing Calculator.java
Run javac Calculator.java && jar -cf Calculator.jar Calculator.class. You should see a Calculator.jar file afterwards.
Create a new Android Binding Project and add Calculator.jar to it.
Build the project.
Open the Object Browser (View > Object Browser), click the dropdown at the top of the window, and click My Solution.
Find the binding project in the list and find the ICalculator interface in the Com.Example.Calculator namespace, right-click on it and click Go To Definition.
The interface code will show up, and you'll see that even though there's a Subtract method, no Add method was generated.
Did you find any workaround?
I encountered the issue while creating a binding for the Twilio Conversations Android SDK. The only workaround I could come up with was to manually write the interface method & its invoker implementation.
Wow, it worked!
I wish I had known this earlier. Please consider adding this information to the main Xamarin.Android binding documentation.
Thank you very much!
Activity
jpobst commentedon Jun 24, 2022
We never turned this on by default for Classic binding projects. You will need to add the
<_EnableInterfaceMembers>property mentioned here:https://docs.microsoft.com/en-us/xamarin/android/release-notes/10/10.1#c-80-default-interface-members-for-bindings-projects
In a .NET 6+ binding this is on by default and can be disabled with:
https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/OneDotNetBindingProjects.md#static-and-default-interface-members-dim
jedusei commentedon Jun 24, 2022
Wow, it worked!
I wish I had known this earlier. Please consider adding this information to the main Xamarin.Android binding documentation.
Thank you very much!