Java Bindings .AAR // Proper Type for JavaCast?

What type should there be here for this to work?

 
I am currently working on the java bindings for the Android library Anvil. Aiming to get the library working on Xamarin.
However compiling the .aar library during the Importing process as described in the Xamarin documentation results in an error with faulty casting.
The problem is that the generated code is trying to convert Java.Lang.Integer to Android.Runtime.IJavaObject.
Apply method should try to cast the lists as Android.Runtime.JavaList instead of the current Syste.Collections.Generic.IList.

This is the current generated C# output from the .aar:

static IntPtr id_apply_Landroid_view_View_Ljava_util_List_Ljava_util_List_;
// Metadata.xml XPath method reference: path="/api/package[@name='trikita.anvil']/class[@name='BaseDSL.LayoutMarginFunc']/method[@name='apply' and count(parameter)=3 and parameter[1][@type='android.view.View'] and parameter[2][@type='java.util.List<java.lang.Integer>'] and parameter[3][@type='java.util.List<java.lang.Integer>']]"
[Register ("apply", "(Landroid/view/View;Ljava/util/List;Ljava/util/List;)V", "")]
public unsafe void Apply (global::Android.Views.View p0, global::System.Collections.Generic.IList<global::Java.Lang.Integer> p1, global::System.Collections.Generic.IList<global::Java.Lang.Integer> p2)
{
    //...
}

// This method is explicitly implemented as a member of an instantiated Trikita.Anvil.Anvil.IAttrFunc
void global::Trikita.Anvil.Anvil.IAttrFunc.Apply (global::Android.Views.View p0, global::Java.Lang.Object p1, global::Java.Lang.Object p2)
{
    Apply (p0, global::Java.Interop.JavaObjectExtensions.JavaCast<global::System.Collections.Generic.IList<global::Java.Lang.Integer>>(p1), global::Java.Interop.JavaObjectExtensions.JavaCast<global::System.Collections.Generic.IList<global::Java.Lang.Integer>>(p2));
}

 

Error Message from the generated code:

"/Users/~/xamarin/AnvilTest/Anvil/obj/Debug/generated/src/Trikita.Anvil.BaseDSL.cs(58,58): 
Error CS0311: 
The type System.Collections.Generic.IList<Java.Lang.Integer> cannot be used as type parameter TResult in the generic type or method 

Java.Interop.JavaObjectExtensions.JavaCast(this Android.Runtime.IJavaObject). There is no implicit reference conversion from
System.Collections.Generic.IList<Java.Lang.Integer> to Android.Runtime.IJavaObject (CS0311) (Anvil)"

 

Part of the Java class we're trying to create bindings for:

private final static class LayoutSizeFunc
        implements Anvil.AttrFunc<Map.Entry<Integer, Integer>> {
    private final static LayoutSizeFunc instance = new LayoutSizeFunc();
    public void apply(View v, Map.Entry<Integer, Integer> arg,
            Map.Entry<Integer, Integer> old) {
        ViewGroup.LayoutParams p = v.getLayoutParams();
        p.width = arg.getKey();
        p.height = arg.getValue();
        v.setLayoutParams(p);
    }
}

 

This is an example of what it should look like and what we're looking for. Compiling version with Android.Runtime.JavaList<global::Java.Lang.Integer>.

static IntPtr id_apply_Landroid_view_View_Ljava_util_List_Ljava_util_List_;
// Metadata.xml XPath method reference: path="/api/package[@name='trikita.anvil']/class[@name='BaseDSL.LayoutMarginFunc']/method[@name='apply' and count(parameter)=3 and parameter[1][@type='android.view.View'] and parameter[2][@type='java.util.List&lt;java.lang.Integer&gt;'] and parameter[3][@type='java.util.List&lt;java.lang.Integer&gt;']]"
[Register ("apply", "(Landroid/view/View;Ljava/util/List;Ljava/util/List;)V", "")]
public unsafe void Apply (global::Android.Views.View p0, global::System.Collections.Generic.IList<global::Java.Lang.Integer> p1, global::System.Collections.Generic.IList<global::Java.Lang.Integer> p2)
{
    //...
}

// This method is explicitly implemented as a member of an instantiated Trikita.Anvil.Anvil.IAttrFunc
void global::Trikita.Anvil.Anvil.IAttrFunc.Apply (global::Android.Views.View p0, global::Java.Lang.Object p1, global::Java.Lang.Object p2)
{
    Apply (p0, global::Java.Interop.JavaObjectExtensions.JavaCast<global::Android.Runtime.JavaList<global::Java.Lang.Integer>>(p1), global::Java.Interop.JavaObjectExtensions.JavaCast<global::Android.Runtime.JavaList<global::Java.Lang.Integer>>(p2));
}

 

Modifying the generated code with the Metadata.xml file gives some results with naming and visibility problems, but further modifications are unfortunately out of reach.

Sign In or Register to comment.