menu

Questions & Answers

MAUI and platform binding libraries

I'm trying to setup a MAUI app primarily for Windows and Android devices. I have a BT printer that the supplier provides libraries (in form of JAR and DLL files) for.

I'm trying to add to the MAUI app the JAR library using the Android Java Library Binding as a separate project. The project builds itself but, when I add to the MAUI app, I receive errors regarding the lack of support by the library for other platforms (iOS, Windows).

Reading some other threads the solution should be to add a MAUI class library (where for every platform I can add specific code) but I don't know how can wrap the JAR library into it for Android.

In Xamarin Forms it's more simple: refer the Android Binding Library (Xamarin) by the app.android project and all is done.

So can I do the same for MAUI? Can I have one printer library for every platform I want to support and, via iOC, refer the right library for the right platform?

Thanks in advance Andrea.

Answers(1) :

just for someone that has the same question, I have resolved editing by hand the csproj file and adding conditional project referencing like this:

<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-android31.0' ">
    <ProjectReference Include="..\Your.CodeFor.Android\Your.CodeFor.Android.csproj" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net6.0-windows10.0.19041.0' ">
  <ProjectReference Include="..\Your.CodeFor.Windows\Your.CodeFor.Windows.csproj" />
</ItemGroup>

Now I can specify different project reference for different platforms, only an IntelliSense warning appears when use the reference that lacks code for platforms that is not intended for.

Andrea.