Java Binding Abstract class not being generated

2020-02-10 09:42发布

问题:

Error CS0234: The type or namespace name IBitmap' does not exist in the namespaceCom.Sushi.Hangover'. Are you missing an assembly reference?

I have an Android binding project which has classes that are inheriting from multiple interfaces but these interfaces are not been generated and thus all of the public classes that depend upon them are failing to bind.

Java Class:

abstract interface Bitmap
{
   ~~~ (methods removed)
}

api.xml:

<interface abstract="true" deprecated="not deprecated" final="false" name="Bitmap" static="false" visibility="">

As you can see the visibility of this interface is not set to public and thus no C# code is generated, but there are public classes begin generated that depend on this interface:

public partial class DrawableDesign : global::Com.Sushi.Hangover.IBitmap {

The binding is aware of the interface as it transforming the interface name from Bitmap to IBitmap.

Is there any way to force these interfaces to be created without going back the Java code and changing these interfaces to public to get them into the api.xml as visibility="public"?

Note: I am on stable channel (Xamarin.Android Version: 6.0.3.5) as this client does not have Alpha/Beta access

回答1:

I've written a smallish guide on this topic that might help in certain areas: https://gist.github.com/JonDouglas/dda6d8ace7d071b0e8cb

In short, you could potentially try changing the visibility like @Cheesebaron has mentioned already: https://gist.github.com/JonDouglas/dda6d8ace7d071b0e8cb#class-visibility (Replace /class with interface or read the common paths)

Otherwise you can potentially try to add the node from scratch: https://gist.github.com/JonDouglas/dda6d8ace7d071b0e8cb#adding-types

For a more exact answer, I believe we would need to see the respective .jar/.aar and the current Bindings project.



回答2:

In your binding library inside of the Transforms/Metadata.xml file you can change the visibility by adding the following line:

<attr path="/api/package[@name='com.sushi.hangover']/interface[@name='IBitmap']" name="visibility">public</attr>

Given that the package name in Java world is com.sushi.hangover and interface name is IBitmap.

You can read some more about the format of attr in the GAPI mono documentation. There is also some nice bindings documentation in the Xamarin Docs.