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
201 stars 52 forks source link

Problem with generating default interface #749

Closed farshaddavoudi closed 3 years ago

farshaddavoudi commented 3 years ago

Hi,

According to Xamarin.Android 10.1 release notes the jar library which is using the default interface feature of Java will be generated properly with C# equivalent. But when I created a super simple Java app including a default interface, it throws an error in output window (visible only when output verbosity set to detailed) as below image:

image (NumberManager is the interface)

So what's wrong here? I don't understand. I created a Xamarin Binding project in VS and put the jar file into Jars folder and set the Build Action of that lib to EmbeddedJar and finally added the lines noted in the release note (top link) in the project csproj to do the majic. But that error really bothers me. I need it to work on a real project. Can anyone help?

I attached the Java test project. It includes a very simple public class and public interface with Java default feature to test generating into Xamarin project. The Jar will work when executing it as a standalone library with the command line help.

Will appreciate it if somebody helps me out.

Thanks

java_src.zip

jpobst commented 3 years ago

I think the issue isn't related to default interface methods. Even without them, INumberManager would still be created, it just would not contain the Change method.

The issue is that something doesn't seem to correctly handle types that are not in a package. Adding package com.blah2; to your .java files seems to fix it.

farshaddavoudi commented 3 years ago

Thanks, Jonathan. I was working so hard these two days to make it work with your suggestion and without bothering you with more questions and it finally worked!

Best regard!