Binding Android Library - add new method into class generated from jar <add-node>?

Leonard Harris 6 Reputation points
2021-03-11T01:29:09.82+00:00

I've got a situation where I need to add a new method into a class, the class is called Preconditions and the class is generated from a jar file so I am working within the additions and the metadata.xml in transformations folder to generate a new method in the final api.xml

How does one add a method into a class generated from a jar file?

The method is called checkNotNullFromProvides and in the Preconditions.class file looks like this:

public static <T> T checkNotNullFromProvides(T reference) {
    if (reference == null)
      throw new NullPointerException("Cannot return null from a non-@Nullable @Provides method"); 
    return reference;
  }

And so I have added into my additions the class i.e. Preconditions.cs

public partial class Preconditions
    {
        public static T checkNotNullFromProvides<T>(T reference)
        {
            if (reference == null)
                throw new NullReferenceException("Cannot return null from a non-@Nullable @Provides method");
            return reference;
        }
    }

Then in my Metadata.xml I have try to add the node which is the new method in the class:

<add-node path="/api/package[@name='dagger.internal']/class[@name='Preconditions']">
    <method abstract="false" native="false" deprecated="not deprecated" final="false"  name="checkNotNullFromProvides" return="T" static="true" synchronized="false" visibility="public">
      <parameter name="reference" type="T"/>
    </method>
  </add-node>

Unfortunately when I look into the api.xml the new method does not show up so how does one add a new method to a binding library so it gets included in the final api?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,288 questions
{count} votes