I want to use a .jar file that I have with my Xamarin.Android project.
After I create the binding project and try to build, I get this error:
obj\Debug\generated\src\Com.Acrcloud.Rec.Sdk.Utils.ACRCloudGetIPAddressAsyncTask.cs(23,23): Error CS0534: 'ACRCloudGetIPAddressAsyncTask' does not implement inherited abstract member 'AsyncTask.DoInBackground(params Object[])' (CS0534)
Using a decompiler, I checked the contents of ACRCloudGetIPAddressAsyncTask
and found this:
package com.acrcloud.rec.sdk.utils;
import android.os.AsyncTask;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class ACRCloudGetIPAddressAsyncTask
extends AsyncTask<String, Integer, String>
{
private static final String TAG = "ACRCloudAsynGetIPAddressTask";
protected String doInBackground(String... params)
{
String ip = "";
try
{
InetAddress x = InetAddress.getByName(params[0]);
ip = x.getHostAddress();
}
catch (UnknownHostException e)
{
e.printStackTrace();
ip = "";
}
catch (Exception e2)
{
ip = "";
}
return ip;
}
protected void onPostExecute(String ip)
{
super.onPreExecute();
ACRCloudLogger.d("ACRCloudAsynGetIPAddressTask", ">>>>>>>>>>>>>>> " + ip);
com.acrcloud.rec.sdk.recognizer.ACRCloudRecognizerRemoteImpl.serverIP = ip;
}
}
Why do I even need to implement DoInBackground(params Object[])
? The generated C# code implemented protected virtual unsafe string DoInBackground (params string[] @params)
to match what's in the Java code...I don't know a lot about Java so I'm probably missing something...any idea how I can fix this?
You can check this great post: Approaching a Xamarin.Android Bindings Case, by checking the Adding Types part, it uses <add-node>
when we want to add a class, change a constructor, or switch a generic type.
For your lib, you can open the Metadata.xml
under the Transforms
folder, and then add this code:
<add-node path="/api/package[@name='com.acrcloud.rec.sdk.utils']">
<class abstract="false" deprecated="not deprecated" final="false" name="ACRCloudLocalRecognizerInitAsyncTask" static="true" visibility="public" extends="java.lang.Object">
</class>
<class abstract="false" deprecated="not deprecated" final="false" name="ACRCloudGetIPAddressAsyncTask" static="true" visibility="public" extends="java.lang.Object">
</class>
</add-node>
Then it can be successfully compiled, but I didn't test to reference this lib to Xamarin.Android project, you may need further research for using this lib. Anyway, that post helps a lot.
You can also check the similar case on SO: Java Binding Abstract class not being generated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With