3

I'm currently trying to get the SDK, that's written in java (.jar file), to work with Xamarin.Android. Therefore, I'm trying to bind the .jar file by following the official tutorial (https://learn.microsoft.com/en-us/xamarin/android/platform/binding-java-library/binding-a-jar). How do I get rid of the warnings 'warning BG8102: Class X has unknown base type Y.' without having the source code ?

Unfortunately, I haven't had that much success, since only a small part of the classes would bind correctly. I looked into the console and saw a lot of similar warnings 'warning BG8102: Class Wangpos.Sdk4.Libbasebinder.IDCard has unknown base type wangpos.sdk4.libbasebinder.a.'. All of the other warning were mostly the same - only the classes differ (base type stays the same). I have tried dissasembling the .jar SDK files, however the base class 'a' doesn't seem out of the ordinary. No additional references except the java native ones.

A short snippet of the dissasembled class.


import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.IBinder.DeathRecipient;
import android.os.RemoteException;
import android.util.Log;
import java.util.concurrent.CountDownLatch;
import wangpos.sdk4.base.IBinderPool;


public class a
{
  private static final String a = "BaseBinder";
  public static final int BINDER_NONE = -1;
  private Context c;
  private static IBinderPool d = null;

  private static a e;
  private CountDownLatch f;
  protected boolean b = false;

  private a(Context context) {
    c = context;
    d = null;
    c();
  }


  public a() {}

  static a a(Context context)
  {
    if (d == null) {
      synchronized (a.class) {
        if (d == null) {
          e = new a(context);
        }
      }
    }
    return e;
  }

  private ServiceConnection g = new BaseBinder.1(this);
  ...
}

Corresponding section of the generated api.xml file:

    <class abstract="false" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" jni-extends="Ljava/lang/Object;" final="true" name="a" static="false" visibility="public" jni-signature="Lsdk4/wangpos/libemvbinder/a;">
      <constructor deprecated="not deprecated" final="false" name="a" jni-signature="()V" bridge="false" static="false" type="sdk4.wangpos.libemvbinder.a" synthetic="false" visibility="public">
      </constructor>
      <field deprecated="not deprecated" final="true" name="a" jni-signature="Z" static="true" transient="false" type="boolean" type-generic-aware="boolean" visibility="public" volatile="false">
      </field>
      <field deprecated="not deprecated" final="true" name="b" jni-signature="Ljava/lang/String;" static="true" transient="false" type="java.lang.String" type-generic-aware="java.lang.String" value="&quot;sdk4.wangpos.libemvbinder&quot;" visibility="public" volatile="false">
      </field>
      <field deprecated="not deprecated" final="true" name="c" jni-signature="Ljava/lang/String;" static="true" transient="false" type="java.lang.String" type-generic-aware="java.lang.String" value="&quot;debug&quot;" visibility="public" volatile="false">
      </field>
      <field deprecated="not deprecated" final="true" name="d" jni-signature="Ljava/lang/String;" static="true" transient="false" type="java.lang.String" type-generic-aware="java.lang.String" value="&quot;&quot;" visibility="public" volatile="false">
      </field>
      <field deprecated="not deprecated" final="true" name="e" jni-signature="I" static="true" transient="false" type="int" type-generic-aware="int" value="1" visibility="public" volatile="false">
      </field>
      <field deprecated="not deprecated" final="true" name="f" jni-signature="Ljava/lang/String;" static="true" transient="false" type="java.lang.String" type-generic-aware="java.lang.String" value="&quot;1.3&quot;" visibility="public" volatile="false">
      </field>
    </class>

No corresponding .cs file is generated for this class.

UPDATE: Link to .jar SDK files, for everyone to try: https://www.dropbox.com/sh/msy3pa65x6u1ou7/AACb0rZBo3u3g33-XuRA7U6Ca?dl=0

Finally, the expected result would be a full or almost full SDK classes availability in c# as a result of .jar binding.

Since I'm new to java binding in xamarin, any tips are much appreciated.

Jonas Petraška
  • 130
  • 1
  • 9
  • try to add this into your Metadata,xml `false` ,if possible,you could share your library for test – Leo Zhu Jun 27 '19 at 03:10
  • I have added links to SDK files. I will try the suggested fix a bit later and let you know how it goes. – Jonas Petraška Jun 27 '19 at 06:18
  • @LeoZhu-MSFT Indeed, adding the transformation you mentioned, alongside similar transformations for other classes, fixed it - now the .cs file is generated and the class is exposed to my project. Unfortunately, calling the constructor of "Printer" class hangs on me without any exceptions (specifically on method _members.InstanceMethods.FinishCreateInstance). There are many more warning, so I hope they are the cause for the constructor hanging. However, this is a topic for another question. – Jonas Petraška Jun 27 '19 at 07:54
  • ok,may i post it as an answer to this question,and you could open another question,then could continue to talk about it – Leo Zhu Jun 27 '19 at 08:03
  • @LeoZhu-MSFT yes, please do post it as an answer. – Jonas Petraška Jun 27 '19 at 08:04

1 Answers1

2

Typically we will see characteristics of obfuscated types in our respective .jar/.aar libraries and we must unobfuscate them for the Bindings Generator to generate the respective C# types.

you could try this,in your libarary - Transforms - Metadata.xml add:

<attr path="/api/package[@name='{package_name}']/class[@name='{name}']" name="obfuscated">false</attr>
Leo Zhu
  • 15,726
  • 1
  • 7
  • 23