Author Topic: proper way to add bass.xcframework for ios to dotnet maui in MSBuild  (Read 530 times)

serkanp

  • Posts: 135
hi @ian and @radio42
i have dotnet maui project and want to add bass.xcframework
in my root folder of project , i added libs with sub folders:
MauiApp\Frameworks\bass.xcframework
MauiApp\Frameworks\bassmix.xcframework
MauiApp\Frameworks\bassenc_mp3.xcframework

and in my csproj file of project, i added:
Code: [Select]
<ItemGroup>
<NativeReference Include="Frameworks\bass.xcframework">
      <Kind>Framework</Kind>
      <Frameworks></Frameworks>
</NativeReference>
</ItemGroup>

when i build the project for ios,
i get
Frameworks/bass.xcframework has an incorrect or unknown format and cannot be processed

so please someone can give me a proper way to add it to msbuild both for simulator and real device and load in c# side ..
i spend 2 days and there is no information how to add xcframework folders..
helppppp!!!! :)))


radio42

  • Posts: 4833
I have never used Maui myself, so I am sorry but I
might not be of great help.

serkanp

  • Posts: 135
I have never used Maui myself, so I am sorry but I
might not be of great help.

ok so for an ios project, not maui, what is the proper way to add it to msbuild?

serkanp

  • Posts: 135
at last i solved it..
for whom suffers from same problem on maui or maui blazor app
create a folder on root of your project , name it Frameworks
put xcframework folders directly to here (ex: bass.xcframework)

then open cspoj file and add these:

Code: [Select]

   <Target Name="CopyBassFrameworks" BeforeTargets="PrepareForBuild" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<!-- Diagnostic message -->
<Message Text="Starting CopyBassFrameworks target." Importance="high" />
<Message Text="Copying for iOS Device..." Importance="high" Condition="'$(RuntimeIdentifier)' != 'iossimulator-x64'" />
<Message Text="Copying for iOS Simulator..." Importance="high" Condition="'$(RuntimeIdentifier)' == 'iossimulator-x64'" />

<ItemGroup Condition="'$(RuntimeIdentifier)' != 'iossimulator-x64'">
<!-- bass framework -->
<BassFramework Include="$(MSBuildThisFileDirectory)Frameworks\bass.xcframework\ios-arm64_armv7_armv7s\bass.framework\**" />
<!-- bassmix framework -->
<BassMixFramework Include="$(MSBuildThisFileDirectory)Frameworks\bassmix.xcframework\ios-arm64_armv7_armv7s\bassmix.framework\**" />
<!-- bassenc framework -->
<BassEncFramework Include="$(MSBuildThisFileDirectory)Frameworks\bassenc.xcframework\ios-arm64_armv7_armv7s\bassenc.framework\**" />
<!-- bassenc_mp3 framework -->
<BassEncMp3Framework Include="$(MSBuildThisFileDirectory)Frameworks\bassenc_mp3.xcframework\ios-arm64_armv7_armv7s\bassenc_mp3.framework\**" />
</ItemGroup>

<!-- For the simulator -->
<ItemGroup Condition="'$(RuntimeIdentifier)' == 'iossimulator-x64'">
<!-- bass framework -->
<BassFramework Include="$(MSBuildThisFileDirectory)Frameworks\bass.xcframework\ios-arm64_i386_x86_64-simulator\bass.framework\**" />
<!-- bassmix framework -->
<BassMixFramework Include="$(MSBuildThisFileDirectory)Frameworks\bassmix.xcframework\ios-arm64_i386_x86_64-simulator\bassmix.framework\**" />
<!-- bassenc framework -->
<BassEncFramework Include="$(MSBuildThisFileDirectory)Frameworks\bassenc.xcframework\ios-arm64_i386_x86_64-simulator\bassenc.framework\**" />
<!-- bassenc_mp3 framework -->
<BassEncMp3Framework Include="$(MSBuildThisFileDirectory)Frameworks\bassenc_mp3.xcframework\ios-arm64_i386_x86_64-simulator\bassenc_mp3.framework\**" />
</ItemGroup>

<!-- Diagnostic messages -->
<Message Text="Platform is: $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)'))" Importance="high" />
<Message Text="Platform2 is: $(RuntimeIdentifier)" Importance="high" />
<Message Text="ProjectDir is: $(ProjectDir)" Importance="high" />

<Message Text="Copying files from bass framework: @(BassFramework)" Importance="high" />
<Message Text="Copying files from bassmix framework: @(BassMixFramework)" Importance="high" />
<Message Text="Copying files from bassenc_mp3 framework: @(BassEncMp3Framework)" Importance="high" />

<Copy SourceFiles="@(BassFramework)" DestinationFolder="$(ProjectDir)bass.framework\%(RecursiveDir)" />
<Copy SourceFiles="@(BassMixFramework)" DestinationFolder="$(ProjectDir)bassmix.framework\%(RecursiveDir)" />
<Copy SourceFiles="@(BassEncFramework)" DestinationFolder="$(ProjectDir)bassenc.framework\%(RecursiveDir)" />
<Copy SourceFiles="@(BassEncMp3Framework)" DestinationFolder="$(ProjectDir)bassenc_mp3.framework\%(RecursiveDir)" />

<!-- Diagnostic message -->
<Message Text="Finished copying frameworks to: $(ProjectDir)" Importance="high" />
</Target>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">
<NativeReference Include="$(ProjectDir)\bass.framework">
<Kind>Framework</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
</NativeReference>
<NativeReference Include="$(ProjectDir)\bassmix.framework">
<Kind>Framework</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
</NativeReference>
     <NativeReference Include="$(ProjectDir)\bassenc.framework">
<Kind>Framework</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
</NativeReference>
    <NativeReference Include="$(ProjectDir)\bassenc_mp3.framework">
<Kind>Framework</Kind>
<SmartLink>True</SmartLink>
<ForceLoad>True</ForceLoad>
</NativeReference>
</ItemGroup>

add other plugins as you need..
then use
Code: [Select]
public static class BassHelper
{


    public static nint ImportResolver(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
    {
        nint libHandle = 0;

        if (libraryName.StartsWith("bass"))
        {
#if WINDOWS
NativeLibrary.TryLoad($"{libraryName}.dll", out libHandle);
#elif __ANDROID__
            NativeLibrary.TryLoad($"{libraryName}.so", assembly, DllImportSearchPath.ApplicationDirectory, out libHandle);
#elif __IOS__
NativeLibrary.TryLoad($"./Frameworks/{libraryName}.framework/{libraryName}", assembly, DllImportSearchPath.ApplicationDirectory, out libHandle);
#else
CrossPlatform.Assert(false);
#endif
        }

        return libHandle;
    }
}

and call like this
Code: [Select]
try
        {

#if IOS
NativeLibrary.SetDllImportResolver(typeof(BassNet).Assembly,BassHelper.ImportResolver);
#endif
            var init = Bass.BASS_Init(-1, 44100, BASSInit.BASS_DEVICE_DEFAULT, IntPtr.Zero);
            var mixer = BassMix.BASS_Mixer_StreamCreate(44100, 2, BASSFlag.BASS_DEFAULT);
            var en1 = BassEnc.BASS_Encode_GetVersion();
            var en2 = BassEnc_Mp3.BASS_Encode_MP3_GetVersion();

        }
        catch (Exception ex)
        {

        }

note for @ian and @radio42
without adding bassenc.xcframework , bassenc_mp3.framework not works
is this normal?

Ian @ un4seen

  • Administrator
  • Posts: 25614
without adding bassenc.xcframework , bassenc_mp3.framework not works
is this normal?

Yes, that is correct. BASSenc_MP3 (and BASSenc_AAC/FLAC/OGG/OPUS) requires BASSenc.

serkanp

  • Posts: 135
without adding bassenc.xcframework , bassenc_mp3.framework not works
is this normal?

Yes, that is correct. BASSenc_MP3 (and BASSenc_AAC/FLAC/OGG/OPUS) requires BASSenc.

ok perfect.. thanx for correction..
now bass works in dotnet maui , Blazor Hybrid apps (which app works like electron or flutter.. app can run on any platform.. macos, windows,ios,tizen, android etc.. )

so ian one more question, i know tizen can accept c, c++ codes on apps..
do you have any plans porting bass to tizen ?


Ian @ un4seen

  • Administrator
  • Posts: 25614
I don't know much about Tizen except that it's based on Linux. Perhaps the existing Linux BASS version can be used with it?