LeonardHarris-3315 avatar image
0 Votes"
LeonardHarris-3315 asked LeonardHarris-3315 edited

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

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"/>

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?

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Compared with your xml with existing add-node method, looks good to me. Is it possible to make the Preconditions class not "partial" and have a try?

0 Votes 0 ·

@NicoleLu-9366 revising this issue, removing the partial gives red squiggly line see below


I set build output to diagnostic and T is unrecognized so changed it to Java.Lang.Object and I think resolved that issue. Another issue I encountered was the method I was trying to add was in both additions class and metadata.xml and it was saying about duplicate method exists so I removed the additions method and just kept it in the metadata.xml and it generated the below in my Preconditions class, oddly enough however I couldn't find the method in the api.xml in the obj so its not being included in the final generated API. How does it end up in the .dll generated from the binding library but not the api.xml? That's what I cant figure out


0 Votes 0 ·
untitled.png (19.3 KiB)
capture.png (165.1 KiB)

0 Answers