0

I have a .net Maui Native iOS binding of some iOS framework. I managed to bind successfully. However, I want to create a .Net Maui Class library to consume the iOS native binding. See my project structure below:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net7.0;net7.0-android;net7.0-ios</TargetFrameworks>
        <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
        <!-- <TargetFrameworks>$(TargetFrameworks);net7.0-tizen</TargetFrameworks> -->
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>enable</ImplicitUsings>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">16.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net7.0-ios|AnyCPU'">
      <CreatePackage>false</CreatePackage>
    </PropertyGroup>
    <ItemGroup>
      <ProjectReference Include="..\NativeSdk.Android\NativeSdk.Android.csproj" />

      <ProjectReference Include="..\NativeSdk.iOS\NativeSdk.iOS.csproj" />
    </ItemGroup>
    <ItemGroup Condition=" '$(TargetFramework)' == 'net7.0-ios' ">
  <ProjectReference Include="Path\To\Your\iOSNativeBindingProject.csproj" />
</ItemGroup>
    <ItemGroup>
      <None Remove="Platforms\Android\Models\" />
      <None Remove="Platforms\Android\Aar\" />
      <None Remove="Platforms\Android\Aar\TransaktSDK.aar" />
    </ItemGroup>
    <ItemGroup>
      <Folder Include="Platforms\Android\Models\" />
      <Folder Include="Platforms\Android\Aar\" />
    </ItemGroup>
    <ItemGroup>
       <AndroidAarLibrary Include="Platforms\Android\Aar\TransaktSDK.aar">
          <AndroidSkipResourceProcessing></AndroidSkipResourceProcessing>
      </AndroidAarLibrary>
    </ItemGroup>
    <ItemGroup>
      <Compile Condition=" '$(EnableDefaultCompileItems)' == 'true' " Update="SecureServiceInfo.cs">
        <ExcludeFromCurrentConfiguration>true</ExcludeFromCurrentConfiguration>
      </Compile>
    </ItemGroup>
</Project>

I tried to add to add the other platforms on my Native binding project to avoid compatibility issues. I also added condtions to try to only compile with ios. When I do that all the files in the apiDefinition class break. See below my native iOS project

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   <TargetFrameworks>net7.0-ios;net7.0;net7.0-android;net7.0-maccatalyst</TargetFrameworks>
    <Nullable>enable</Nullable>
    <ImplicitUsings>true</ImplicitUsings>
    <IsBindingProject>true</IsBindingProject>
  </PropertyGroup>

<!--  <ItemGroup>
    <Compile Remove="StructsAndEnums.cs" />
    <Compile Remove="ApiDefinitions.cs" />
  </ItemGroup>-->
  <ItemGroup>
    <ObjcBindingCoreSource Include="StructsAndEnums.cs" />
  </ItemGroup>
  <ItemGroup>
    <ObjcBindingApiDefinition Include="ApiDefinitions.cs" />
  </ItemGroup>
  <ItemGroup Condition="'$(TargetFramework)' == 'net7.0-ios'">
    <NativeReference Include="..\..\..\..\..\Downloads\nativeSKD_iOS\NativeSDK.xcframework">
      <Kind>Framework</Kind>
      <Frameworks>Foundation</Frameworks>
      <ForceLoad>True</ForceLoad>
    </NativeReference>
  </ItemGroup>
</Project>

I've been stuck on this for days. I just want to create a maui class library including my native iOS binding project

2 Answers 2

0

Why do you want to create a MAUI Class Library? You can reference the dll created by the iOS Binding Library directly in a .NET MAUI App project. Or you can create a nuget from the iOS Binding Library and consume that in a .NET MAUI App project.

Sign up to request clarification or add additional context in comments.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

unfortunately you have long steps ahead :-/

MAUI same as Xamarin, have lot of configurations that has to be done precisely.

From your example, I cannot see

<ObjcBindingApiDefinition Include="..\NativeSdk.iOS\ApiDefinitions.cs" />

That ^ has to be generated by Sharpie tool. Also Sharpie output is not 100% correct, you have to fix some parts here and there.

Then, your looks almost fine, please add SmartLink:

<NativeReference Include="..\..\..\..\..\Downloads\nativeSKD_iOS\NativeSDK.xcframework">
  <Kind>Framework</Kind>
  <Frameworks>Foundation</Frameworks>
  <ForceLoad>True</ForceLoad>
  <SmartLink>False</SmartLink>
</NativeReference>

Otherwise ForceLoad will be ignored (depends on env conf, but add it to be sure).

And last advise, you should write here an error that you see, otherwise it is truly try-and-fail hints from us.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.