我想创建一个引用和调用代码.JAR Java 库的.NET MAUI 应用程序。我正在按照 Xamarin 说明进行绑定 .JAR。这涉及创建一个 Android Java Library Binding 项目并向其中添加 *.jar 文件。但是,我无法完成网页上的说明:它告诉我将 .jar 文件的 Build Action 设置为
EmbeddedJar
,但我没有此选项。
从 Visual Studio 2022(版本 17.7.0 预览版 6.0)开始,设置 Android Java 库绑定项目以便从 .jar 文件生成 C# 绑定类的正确方法是什么?
我不知道为什么属性窗口中缺少
EmbeddedJar
构建操作(可能是因为我使用的是 Visual Studio 的预览版本),但手动编辑 .csproj 文件我能够更改项目类型至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="Libs\sdk-v1.0.0.jar" />
<AndroidLibrary Remove="Libs\slook_v1.4.0.jar" />
</ItemGroup>
<ItemGroup>
<EmbeddedJar Include="Libs\sdk-v1.0.0.jar" />
<EmbeddedJar Include="Libs\slook_v1.4.0.jar" />
</ItemGroup>
</Project>
顺便说一句,我还需要手动修改我的 MAUI 项目中的 .csproj 文件,以向项目引用添加条件,否则我会遇到非 Android 平台代码的构建错误:
<Project Sdk="Microsoft.NET.Sdk">
<!-- ... -->
<ItemGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-android|AnyCPU'">
<ProjectReference Include="..\Samsung.Look\Samsung.Look.csproj" />
</ItemGroup>
</Project>
Now I am able to reference code from the Android Java Library Binding project.