CommunityToolkit / Maui.NativeLibraryInterop

Maui.NativeLibraryInterop is a community-created library of binding samples to help .NET MAUI developers interop with native libraries more easily
MIT License
179 stars 28 forks source link

Unable to bind frameworks that contain bundles #36

Open MerlinTHS opened 4 months ago

MerlinTHS commented 4 months ago

Hi, I'm trying to create a binding library for the Usercentrics framework. The binding for the Usercentrics Core framework works as expected. The binding for the UsercentricsUI framework crashes at runtime when calling any UI related method. UsercentricsUI/ResourceLoader.swift:28: Fatal error: [USERCENTRICS] Cannot load bundle

I have uploaded a sample branch with minimal adjustments (calling Usercentrics methods in GetString) to the NewBinding template. Is there a BuildAction to include bundles at runtime?

silhanji commented 3 months ago

Hi,

not sure if this is the optiaml approach, but I have had a similar issue and resolved it by copying bundle directory into build app. This can be done by adding following into binding project csproj file:

<ItemGroup>
  <Content Include="Path\To\Your\Bundle">
    <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
    <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    <PublishFolderType>RootDirectory</PublishFolderType>
  </Content>
</ItemGroup>
MerlinTHS commented 2 months ago

This results in an build error if I try to use it for a .bundle "file". A workaround is to copy the .bundle into the apps Resources/Raw directory.