1
votes

I'm binding a Xamarin Library from Java and it generates 1 wrong function. The keyword should be override but currently it is virtual.

// Metadata.xml XPath method reference: path="/api/package[@name='com.mapbox.mapboxsdk.tileprovider']/class[@name='MapTileLayerBase.CacheTask']/method[@name='doInBackground' and count(parameter)=1 and parameter[1][@type='java.lang.Object...']]"
[Register ("doInBackground", "([Ljava/lang/Object;)Ljava/lang/Void;", "GetDoInBackground_arrayLjava_lang_Object_Handler")]

protected virtual unsafe global::Java.Lang.Object DoInBackground (params global:: Java.Lang.Object[] p0)

I need to change virtual to override but I don't know how to do that.

I found some comments on the internet say that I should try this one:

<attr path="/api/package[@name='com.mapbox.mapboxsdk.tileprovider']/class[@name='MapTileLayerBase.CacheTask']/method[@name='doInBackground']" name="virtual">false</attr>

I tried but it didn't work.

Do you know how to change it?

4
Have you found the solution? - Sagar Panwala

4 Answers

2
votes

Try:

<attr path="/api/package[@name='com.mapbox.mapboxsdk.tileprovider']/class[@name='MapTileLayerBase.CacheTask']/method[@name='doInBackground']" name="managedOverride">override</attr>

or more hacky way if previous step doesn't work:

<attr path="/api/package[@name='com.mapbox.mapboxsdk.tileprovider']/class[@name='MapTileLayerBase.CacheTask']/method[@name='doInBackground']" name="final">true</attr>
<attr path="/api/package[@name='com.mapbox.mapboxsdk.tileprovider']/class[@name='MapTileLayerBase.CacheTask']/method[@name='doInBackground']" name="visibility">protected override</attr>
1
votes

The solution is to set final to true in the Metadata.xml mapping:

<attr 
   path="/api/package[@name='com.mapbox.mapboxsdk.tileprovider']/class[@name='MapTileLayerBase.CacheTask']/method[@name='doInBackground']"
   name="final">true</attr>

This effectively removes the virtual keyword from the method signature, and doesn't add the final keyword either. Strange behavior, but it works.

0
votes

Are you sure you need this method exposed in your API? You could use approach from this thread http://forums.xamarin.com/discussion/1871/binding-java-library-with-parameter-type-void and just remove this method. Usually methods like this are not explicitly used from the outside.

0
votes

In

  1. in obj/Debug/generated/src find MCW for that class (com.mapbox.mapboxsdk.tileprovider.cs)
  2. copy that file to Additions/ folder and include it into project.
  3. change BuildAction to Compile if neccessary
  4. change virtual to override
  5. that class from process