skip to Main Content

I want to create a .NET MAUI application that references and calls code .JAR Java Library. I’m following Xamarin instructions for Binding a .JAR. This involves creating a Android Java Library Binding project and adding the *.jar files to it. However, I’m not able to complete the instructions on the web page: it tells me to set the Build Action for the .jar file to EmbeddedJar, but I don’t have this option.

Visual Studio Property Window for a .jar file

What’s the correct way to set up a Android Java Library Binding project so that it generates C# binding classes from the .jar files as of Visual Studio 2022 (Version 17.7.0 Preview 6.0)?

2

Answers


  1. Chosen as BEST ANSWER

    I don't know why the EmbeddedJar build action is missing in the Properties Window (perhaps its because I'm using a preview version of Visual Studio), but manually editing the .csproj file I was able to change the item types to EmbeddedJar:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net7.0-android</TargetFramework>
        <SupportedOSPlatformVersion>23.0</SupportedOSPlatformVersion>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <Title>Samsung Edge SDK (Look)</Title>
        <Company>Samsung</Company>
        <PackageProjectUrl>https://developer.samsung.com/galaxy-edge/overview.html</PackageProjectUrl>
        <Description>Galaxy Edge offers specialized widgets and service components for extended functions of the Samsung Android devices. With so many apps and features on your phone, sometimes it takes a while to find what you need. Kind of like speed dial, Edge panels let you access your favorite apps and contents quickly and easily. And to make things better, you can add, remove, or download Edge panels any time you want. You can make it your own and have the information or actions you want available with just a swipe and a tap.</Description>
      </PropertyGroup>
      <ItemGroup>
        <AndroidLibrary Remove="Libssdk-v1.0.0.jar" />
        <AndroidLibrary Remove="Libsslook_v1.4.0.jar" />
      </ItemGroup>
      <ItemGroup>
        <EmbeddedJar Include="Libssdk-v1.0.0.jar" />
        <EmbeddedJar Include="Libsslook_v1.4.0.jar" />
      </ItemGroup>
    </Project>
    

    Incidently, I also needed to manually modify the .csproj file in my MAUI project to add a condition to project reference otherwise I got build errors for non-Android platform code:

    <Project Sdk="Microsoft.NET.Sdk">
       <!-- ... -->
    
        <ItemGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-android|AnyCPU'">
          <ProjectReference Include="..Samsung.LookSamsung.Look.csproj" />
        </ItemGroup>
    
    </Project>
    
    Now I am able to reference code from the Android Java Library Binding project.
    

  2. Embedded Jar type was removed since .net 6 because is it slow.

    There is a documentation here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search