Forum Xamarin.Android

Binding Library fails with 'does not implement inherited abstract member' for synthetic Java methods

mkvonarxmkvonarx USMember
edited March 2015 in Xamarin.Android

I'm trying to bind a rather big JAR library (2MB) and still get 283 'does not implement inherited abstract member' after fixing all the other (mainly non-public base classes) binding issues.

After looking into the JAR file with the Luyten tool and a lot of googling, I found that the problem seems to be related to generic Java types and the synthetic methods that the Java compiler generates for generic types.

An example (Java code decompiled with Luyten):
public abstract class AppenderBase<E> { protected abstract /* Flags: PROTECTED, ABSTRACT */ void append(final E p0); } public class LogcatAppender extends AppenderBase<ILoggingEvent> { public /* Flags: PUBLIC */ void append(final ILoggingEvent loggingEvent) { /* .... */ } }

The Java compiler will generate this method in LogcatAppender too:
public /* Flags: PUBLIC, BRIDGE, SYNTHETIC */ void append(final Object o) { this.append((ILoggingEvent)o); }

Now the generated C# code in the Xamarin binding libarary looks like this:
public abstract partial class AppenderBase { protected abstract void Append (global::Java.Lang.Object p0); } public partial class LogcatAppender : global::CH.Qos.Logback.Core.AppenderBase { public virtual void Append (global::CH.Qos.Logback.Classic.Spi.ILoggingEvent p0) { /* ... */ } }

So there is nothing visible anymore from the Java generics. And the append(Object) method got lost too. And this is the reason why the C# compiler won't compile the generated C# wrapper classes.

Is there any solution to this issue? I know that I could implement these missing overrides in a partial class my self, but I don't want to do this 283 times. And I know that I could hide all affected Java types from the C# binding, but I do need many (most) of the Java types that cause C# compiler problems. So I'm really looking for a third solution.


  • mkvonarxmkvonarx USMember
    edited April 2015

    No replies?

    Some additional observations/questions:
    1. I created a demo JAR File with just one Java interface IDemoInterface and one Java class DemoImplementation to replicate my problem with a controlled setup. "Unfortunately", Xamarin managed to create bindings for that demo project just fine, including the compiler generated synthetic method. Strange. So probably my problems are caused by something else in my 2MB JAR file.
    2. I also have other issues with mapping my 2MB JAR File: Xamarin does not bind some Java types at all (e.g. a class derived from Fragment is missing completely) and other Java types are mapped only partially (e.g. an inner class is missing while the 'outer' class is mapped ok). I checked the file api.xml that is generated by Xamarin's jar2xml.jar and found that these missing types are already missing in api.xml. So this might be jar2xml.jar that does not write these types into api.xml. But why? Any ideas how to find the cause of this?
    3. Is there a way to 'debug' the binding generator, or a verbose log file where I can search for possible reasons for my bindig problems? The files created in the 'obj' directory don't help in the standard verbosity.

  • mkvonarxmkvonarx USMember
    edited April 2015

    (Timeout prevents me from editing my previous comment, so I have to add another one)

    I solved item 2 from my previous comment by 1) adding System.Xml and Xamarin.Android.Support.v4 .NET (support-v4-19.1.0.jar does not work) libraries to the binding project, 2) adding mail.jar as a reference JAR to the binding project, 3) mapping the base class to and 4) un-obfuscating various types in Metadata.xml. The key to find out what to do was actually reading the 300+ warnings and errors in the build output log and find the important ones to give a useful hint (usually lines starting with "BINDINGSGENERATOR : warning").

    My original problem is still unsolved.

  • batmanbatman USMember

    Have you figured out the solution yet? I am having this problem also

  • mkvonarxmkvonarx USMember

    No. My workaround was (is) to hide many of my 283 problems and implement the missing (global::Java.Lang.Object p0) methods in the partial classes for those types that I do need.

  • ChristianGillChristianGill DEMember ✭✭

    Same problem here ... Can someone help please :-(

  • ErhardSmitErhardSmit ZAMember ✭✭

    Has anyone figured this out yet? I also get this:

    Error CS0534: 'Com.Google.Zxing.Client.Result.AddressBookAUResultParser' does not implement inherited abstract member 'Com.Google.Zxing.Client.Result.ResultParser.Parse(Com.Google.Zxing.Result)' (CS0534) (IBApp.ARBinding)

    Cannot seem to find a way to fix it.

  • JasonJensenJasonJensen USUniversity

    ErhardSmit Did you ever solve it? I think I am working on a similar library.

Sign In or Register to comment.