This is a MAUI app running in an Android device, the aar library is provided by a third party unitech vendor, an RFID reader device.
The exception Java.Lang.Exception: 'Bind service failed'
is thrown on the generated code within the Android Java Library Binding
I pass the generated constructor the Platform.CurrentActivity.ApplicationContext
as the only argument. i.e.
<code>reader = new Com.Unitech.Lib.Htx.HT730Reader(Platform.CurrentActivity.ApplicationContext);
<code>reader = new Com.Unitech.Lib.Htx.HT730Reader(Platform.CurrentActivity.ApplicationContext);
</code>
reader = new Com.Unitech.Lib.Htx.HT730Reader(Platform.CurrentActivity.ApplicationContext);
this goes into this generated method:
<code> // Metadata.xml XPath constructor reference: path="/api/package[@name='com.unitech.lib.htx']/class[@name='HT730Reader']/constructor[@name='HT730Reader' and count(parameter)=1 and parameter[1][@type='android.content.Context']]"
[Register (".ctor", "(Landroid/content/Context;)V", "")]
public unsafe HT730Reader (global::Android.Content.Context? context) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
const string __id = "(Landroid/content/Context;)V";
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args);
SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);
_members.InstanceMethods.FinishCreateInstance (__id, this, __args);
global::System.GC.KeepAlive (context);
<code> // Metadata.xml XPath constructor reference: path="/api/package[@name='com.unitech.lib.htx']/class[@name='HT730Reader']/constructor[@name='HT730Reader' and count(parameter)=1 and parameter[1][@type='android.content.Context']]"
[Register (".ctor", "(Landroid/content/Context;)V", "")]
public unsafe HT730Reader (global::Android.Content.Context? context) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
{
const string __id = "(Landroid/content/Context;)V";
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args);
SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);
_members.InstanceMethods.FinishCreateInstance (__id, this, __args);
} finally {
global::System.GC.KeepAlive (context);
}
}
</code>
// Metadata.xml XPath constructor reference: path="/api/package[@name='com.unitech.lib.htx']/class[@name='HT730Reader']/constructor[@name='HT730Reader' and count(parameter)=1 and parameter[1][@type='android.content.Context']]"
[Register (".ctor", "(Landroid/content/Context;)V", "")]
public unsafe HT730Reader (global::Android.Content.Context? context) : base (IntPtr.Zero, JniHandleOwnership.DoNotTransfer)
{
const string __id = "(Landroid/content/Context;)V";
if (((global::Java.Lang.Object) this).Handle != IntPtr.Zero)
return;
try {
JniArgumentValue* __args = stackalloc JniArgumentValue [1];
__args [0] = new JniArgumentValue ((context == null) ? IntPtr.Zero : ((global::Java.Lang.Object) context).Handle);
var __r = _members.InstanceMethods.StartCreateInstance (__id, ((object) this).GetType (), __args);
SetHandle (__r.Handle, JniHandleOwnership.TransferLocalRef);
_members.InstanceMethods.FinishCreateInstance (__id, this, __args);
} finally {
global::System.GC.KeepAlive (context);
}
}
and the exception is thrown in the FinishCreateInstance
line
This is how the binding project looks like
<code><Project Sdk="Microsoft.NET.Sdk">
<TargetFramework>net8.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<None Remove="unitechRFID_v1.0.30.aar" />
<code><Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="unitechRFID_v1.0.30.aar" />
</ItemGroup>
</Project>
</code>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-android</TargetFramework>
<SupportedOSPlatformVersion>21</SupportedOSPlatformVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<None Remove="unitechRFID_v1.0.30.aar" />
</ItemGroup>
</Project>
The same thing works ok in their Xamarin app but I am trying to migrate the example to MAUI
I am not familiar with Android development so I might be missing something basic here.