Forum Cross Platform with Xamarin
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Generated C# classes not nesting java classes correctly

I am trying to Bind the Poynt SDK to C# Using Xamarin's binding library. The .aar file is public for anyone who wants to recreate this

I am having a problem binding the .aar file, after building the solution the classes aren't being nested properly.

IPoyntProductCatalogWithProductListener is an interface that is supposed to contain a nested Stub class that contains a nested Proxy class. Instead the Stub and Proxy are outside of the interface.

I am following the java example app for reference, this is the code I am trying to replicate:

private IPoyntProductCatalogWithProductListener mProdCatWithProdListener = new IPoyntProductCatalogWithProductListener.Stub() {
    @Override
    public void onResponse(CatalogWithProduct catalogWithProduct, PoyntError poyntError) throws RemoteException {
        StringBuilder output = new StringBuilder();
        // products not nested inside a category
        for (CatalogItemWithProduct catalogItem : catalogWithProduct.getProducts()){
            Product product = catalogItem.getProduct();
            output.append("---- ITEM -----\n");
            output.append("Product Name: " + product.getName() + "\n");
            output.append("Product Id: " + product.getId() + "\n");
            output.append("Product Price: " + product.getPrice().getAmount() + "\n");
            Log.d(TAG, "\n"+output);
        }

}
};

As you can see I can't do "IPontProductCatalogWithProductListener.Stub" because it isn't nested. Is there a way I can edit the metadata file so it forces these nested classes. Or is there a work around?

Answers

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    There are some transforms you can define in XML to adjust how the binding libraries are handled.
    Most commonly I make a point of giving real names to the auto-generated parameters p0 and p1 etc.
    Next often I sometimes have to update the type of properties or returns.
    Sometimes you have to rename fields because C# has different naming conventions/restrictions than Java.

    I'll bet that what's happening is that a name/namespace is getting translated badly so everything downstream of that operation (like nesting) gets broken. Before you take the long road of making 100 changes you might find one thing to fix earlier in the process that keeps the rest of the problems from happening.


  • DanielBoyerDanielBoyer USMember

    I have opened the .aar file and it has the names stored as IPoyntProductCatalogWithProductListener, IPoyntProductCatalogWithProductListener$Stub, IPoyntProductCatalogWithProductListener$Stub$Proxy

    I know that this can cause obfuscated cases but I added a line in my metadata setting that to false. I opened the api.xml and it has it as IPoyntProductCatalogWithProductListener.Stub but in the Object Browser it is PoyntProductCatalogWithProductListenerStub. However the Proxy is correctly nested underneath that. Will renaming the files IPoyntProductCatalogWithProductListener.Stub work? @ClintStLaurent

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Will renaming the files IPoyntProductCatalogWithProductListener.Stub work?

    I"m no huge expert on android libraries. Every time I have to import them to a binding lib its a learning experiences. I couldn't just say 'yes' or 'no' to your questions. In the end its always be a case of working with them, and fixing using line by line and gaining a bit more of a 'feel' to doing it each time.

  • RedRaRedRa Member ✭✭✭

    @DanielBoyer Seems like this is common issue for Java Binding Library generator ... (

    Have you fixed this issue ?
    I have the similar issue https://forums.xamarin.com/discussion/184666/xamarin-java-binding-library-multiple-already-defined-errors#latest and cannot figure out how to fix this ...

Sign In or Register to comment.