Java Binding... anyone there??

This place seems pretty quiet!! I have raised a question (https://forums.xamarin.com/discussion/91756/what-is-the-difference-between-api-xml-fixed-and-api-xml) almost 10 days ago and not had any help.

I hope this simple question will raise some sleepy heads :).

The question is basically similar to last question, but simpler...

Has anyone got Java Binding work with a Java library file please? I have created a Java Binding Library project in my Visual Studio 2015, added the JAR file as EmbeddedResource, added some attributes in the MetaData.xml file. The Managed Callable Wrapper C# class does not take my changes in MetaData.xml in the class.

Would be grateful if anyone can give me a pointer if I have done anything incorrect, or missing something.

Thanks in advance.

Tagged:

Answers

  • JohnMillerJohnMiller USForum Administrator, Xamarin Team Xamurai

    @JayMan,

    In case you haven't seen it, this might be helpful: https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-a-jar/

    Are you able to share some more details on what's not working? What did you try and what did you see?

  • JayManJayMan USMember

    Hi John,

    Many thanks for the reply and sorry my message wasn't trying to be negative.

    I have had a look at the example link provided already and trying to do similar to bind a 3rd party JAR file (apologies that I have rename certain names from the Namespace, register attributes, etc. I'm not sure whether I have the consent to show anything from the 3rd party).

    If I could run through the steps, hopefully, I can clarify the problems that I have encountered.

    1. Created a Cross Platform Xamarin solution in Visual studio.
    2. Add a new Binding Library (Android) project into the solution.
    3. Added the JAR file (as EmbeddedJar) into the Jars folder.
    4. Build solution.
    5. In MainActivity.cs of my Android project, I would like to instantiate the MCW class.

    So the first problem is that the MCW class has been created as an abstract class with an internal constructor (as below) and Visual Studio is complaining about it:

    namespace Com.TestSystem.Somemobile.Sdk.Ble {
    
        [Register ("com/testsystems/somemobile/sdk/ble/IMasterDeviceManagerApi", DoNotGenerateAcw=true)]
        public abstract class MasterDeviceManagerApi : Java.Lang.Object {
    
            internal MasterDeviceManagerApi ()
            {
            }
    

    I have examined the generated Api.xml file and I can see that this class has the following declarations:

    <class abstract="false" deprecated="not deprecated" extends="com.testsystems.somemobile.sdk.ble.l" extends-generic-aware="com.testsystems.somemobile.sdk.ble.l" final="true" name="MasterDeviceManagerApi" static="false" visibility="public">
        <constructor deprecated="not deprecated" final="false" name="MasterDeviceManagerApi" static="false" type="com.testsystems.somemobile.sdk.ble.MasterDeviceManagerApi" visibility="public">
            <parameter name="p0" type="android.content.Context">
            </parameter>
        </constructor>
    

    From the above, I can see that there are a number of attributes which do not reflect the generated MCW class:

    • abstract="false" - The class is generated as an abstract class.
    • final="true" - I would have expected the class to be generated as a C# sealed class?
    • extends="com.testsystems.somemobile.sdk.ble.l" - I would have expected the MCW class declaration to be be like - public class MasterDeviceManagerApi : l
    • Constructor visibility="public" - I was expecting this to be made public instead.
    • Constructor declared with parameter, but MCW does not have one.

    I have attempted to try several custom changes in the MetaData.xml, but without success:

    Remove the MasterDeviceManagerApi class and create a new class called JayTestClass

    <remove-node path="/api/package[@name='com.testsystems.somemobile.sdk.ble']/class[@name='MasterDeviceManagerApi']" />
    
    <add-node path="/api/package[@name='com.testsystems.somemobile.sdk.ble']">
        <class abstract="false" deprecated="not deprecated" final="true" name="JayTestClass" static="false" visibility="public" extends="com.testsystems.somemobile.sdk.ble.l">
            <constructor deprecated="not deprecated" final="false" name="JayTestClass" static="false" type="com.testsystems.somemobile.sdk.ble.MasterDeviceManagerApi" visibility="public" />
            <field name="p0" type="android.content.Context" />
        </class>
    </add-node>
    

    Explicitly made declare the class **abstract attribute and constructor to be public**

    <attr path="/api/package[@name='com.saltosystems.justinmobile.sdk.ble']/class[@name='MasterDeviceManagerApi']" name="abstract">false</attr>
    
    <attr path="/api/package[@name='com.saltosystems.justinmobile.sdk.ble']/class[@name='MasterDeviceManagerApi']/method[@name='MasterDeviceManagerApi']" name="visibility">public</attr>
    

    As mentioned in my other post, I can see these custom attributes are applied in a file called api.xml.fixed, but not in the api.xml file, and nothing is changed in my MCW generated class.

    Sorry, it's long winded, but I hope this helps with explaining my problems. Btw, what is the api.xml.fixed file please? I cannot see any documentation on this at all.

    Thanks again John, any help would be much appreciated.

  • JayManJayMan USMember

    Just to add, I have included the code from the Java library that I'm trying to bind (again, some of the namespace have been renamed).

    package com.testsystems.somemobile.sdk.ble;
    
    import android.content.Context;
    import com.testsystems.somemobile.sdk.exceptions.JayException;
    
    public final class MasterDeviceManagerApi
      extends l
    {
      public MasterDeviceManagerApi(Context context)
        throws JayException
      {
        super(context);
      }
    }
    

    Thanks.

  • JayManJayMan USMember

    Really desperate for some help here, is there a premium Support line that we can pay to get some help please? I have spent many days and nights without getting anywhere. Tried the Java binding route (as described), tried JNI route with a little success, but stuck on (maybe a small) problem.

    Is there anyone from Xamarin that can help please? Honestly, we're willing to pay to get some desperate help.

  • LanceKingLanceKing USMember ✭✭

    How did you end up fixing this? Do you have any additional references you could share with others trying to work with Java Binding?

    I am having issues as well and while it's not related to yours so much, I definitely wish there were better resources for Java Binding.

Sign In or Register to comment.