Hello Not new to Maui but new to bringing in a java library for use on android devices.
I’m currently working on a MAUI app that needs to use a third parties .jar file.
I have added the jar file to an Android Binding Library and wrote the metadata.xml. this generates a .dll file for me.
Example snippet of my metadata.xml
<metadata>
<!-- ETermInfoKey -->
<attr path="/api/package[@name='com.pax.dal.entity']/class[@name='ETermInfoKey']" name="managedName">ETermInfoKey</attr>
<attr path="/api/package[@name='com.pax.dal.entity']/class[@name='ETermInfoKey']/field[@name='AP_VER']" name="managedName">ApVer</attr>
<attr path="/api/package[@name='com.pax.dal.entity']/class[@name='ETermInfoKey']/field[@name='BIOS_VER']" name="managedName">BiosVer</attr>
<attr path="/api/package[@name='com.pax.dal.entity']/class[@name='ETermInfoKey']/field[@name='CSN']" name="managedName">Csn</attr>
<attr path="/api/package[@name='com.pax.dal.entity']/class[@name='ETermInfoKey']/field[@name='EXTB_CFG']" name="managedName">ExtbCfg</attr>
......... etc
I’ve added that .dll to my maui project into a folder called Libs
I’ve added the refernce to these and set to always copy
I’ve added some services that consume these to the platform specific section of the maui app
Intellesense is able to resolve this fine like so
using Android.Content;
using Com.Pax.Dal;
using Com.Pax.Dal.Entity;
using Com.Pax.Neptunelite.Api;
namespace TP.Integrated.TerminalApp.Platforms.Android.Neptune;
public class NeptuneService
{
public static IDAL GetDal(Context context)
{
var neptuneLiteUser = NeptuneLiteUser.Instance;
return neptuneLiteUser?.GetDal(context);
}
public static string GetSerialNumber()
{
var dal = GetDal(Platform.AppContext);
var sys = dal.getSys();
var values = sys.getTermInfo();
if (values.Any(x => x.Key == ETermInfoKey.Sn))
{
return values.FirstOrDefault(x => x.Key == ETermInfoKey.Sn).Value;
}
else
{
return null;
}
}
}
But i get build errors for the .java files coming from the dll
I can resolve these by adding a build condition to my reference like so
<!-- Binding Library for Android -->
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
<Reference Include="TP.Integrated.TerminalApp.NeptuneBinding">
<HintPath>LibsTP.Integrated.TerminalApp.NeptuneBinding.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
<None Update="LibsTP.Integrated.TerminalApp.NeptuneBinding.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
But then Intelesense starts to complain about the namespaces in my class instead.
I’ve been googleing and watching a few videos including the one from MAUI about their Interop Binding Solution but that has yielded no help.
I’m not even convinced that i’m doing this the right way but I’ve tried a few and this seems to at least get the class visible in my c# code.