Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to include multiple frameworks file and use in iOS binding library #21579

Open
adarshchiniwar-smartq opened this issue Nov 5, 2024 · 13 comments
Labels
binding-projects Issue or PR that affects binding projects
Milestone

Comments

@adarshchiniwar-smartq
Copy link

adarshchiniwar-smartq commented Nov 5, 2024

Apple platform

iOS

Framework version

net8.0-*

Affected platform version

Visual Studio Community 2022 for Mac Version 17.6.14 (build 413) Installation UUID: d8226832-e953-4619-a882-8fe01192a9c3 Runtime .NET 7.0.3 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2 Roslyn (Language Service) 4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/8.0.402/Sdks SDK Versions: 8.0.402 8.0.401 8.0.400 7.0.317 6.0.425 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Version: 8.0.401 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 9.0.0-rc.1.24431.7 8.0.8 7.0.20 6.0.33 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Version: 8.0.8 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Apple Developer Tools Xcode: 16.0 23051 Build: 16A242d Xamarin.Mac Not Installed Xamarin.iOS Version: 16.4.0.23 Visual Studio Community Hash: 9defd91 Branch: xcode14.3 Build date: 2023-10-23 16:15:00-0400 Xamarin.Android Version: 13.2.2.0 (Visual Studio Community) Commit: xamarin-android/d17-5/45b0e14 Android SDK: /Users/adarshchiniwar/Library/Android/sdk Supported Android versions: None installed SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 35.0.2 SDK Build Tools Version: 35.0.0 Build Information: Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.6.0.50 Hash: a715dca Branch: HEAD Build date: 2024-08-07 17:47:27 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2024-08-07 17:47:27 UTC Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2024-08-07 17:47:20 UTC Build Information Release ID: 1706140413 Git revision: 29d5da805da9895dd02785823633e3bcfabdd769 Build date: 2024-08-07 17:45:52+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 14.5.0 Darwin 23.5.0 Darwin Kernel Version 23.5.0 Wed May 1 20:19:05 PDT 2024 root:xnu-10063.121.3~5/RELEASE_ARM64_T8112 arm64

Description

Hi,

We have got 10 xcframework files that requires for an integration a payment device. I know that we need to create a ApiDefinitions and structsAndEnums.cs using Sharpie, How can i include ApidDefinitions and structsAndEnums.cs for each framework file in iOS Binding library and use it in .net maui project.

Thanks,
Adarsh

Steps to Reproduce

Please help me with the sample project if you have. Below is .csproj file of iOS binding library.

<ItemGroup>
		<NativeReference Include="FPAmaKit.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="FPLoggerKit.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="FPPOICore.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="FPRuaKit.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="FPTetraKit.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="iFCCCore.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="iFCCKit.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="iSAF.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="RUA_MFI.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
		<NativeReference Include="TemLibrary.xcframework">
			<Kind>Framework</Kind>
			<SmartLink>False</SmartLink>
			<ForceLoad>True</ForceLoad>
		</NativeReference>
	</ItemGroup>

Did you find any workaround?

No response

Build logs

No response

@adarshchiniwar-smartq adarshchiniwar-smartq added the binding-projects Issue or PR that affects binding projects label Nov 5, 2024
@rolfbjarne
Copy link
Member

Can you try something like this in the project file?

<ItemGroup>
	<ObjcBindingApiDefinition Include="ApiDefinition1.cs" />
	<ObjcBindingApiDefinition Include="ApiDefinition2.cs" />
	<ObjcBindingApiDefinition Include="ApiDefinition3.cs" />

	<ObjcBindingCoreSource Include="StructsAndEnums1.cs" />
	<ObjcBindingCoreSource Include="StructsAndEnums2.cs" />
	<ObjcBindingCoreSource Include="StructsAndEnums3.cs" />
</ItemGroup>

@rolfbjarne rolfbjarne added the need-info Waiting for more information before the bug can be investigated label Nov 5, 2024
@rolfbjarne rolfbjarne added this to the Future milestone Nov 5, 2024
@adarshchiniwar-smartq
Copy link
Author

Hi,

I’ve been working on payment integration in my .NET MAUI project and explored the alternative template from the Maui.NativeLibraryInterop GitHub. The basic template works fine, and the Android implementation for payment integration also functions as expected.

However, when I include the .xcframework in the Xcode project, the iOS application crashes during the splash screen, with no exception thrown. I would greatly appreciate your help in resolving this issue.

Thanks,
Adarsh

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Nov 7, 2024
@rolfbjarne
Copy link
Member

Please provide the following to try to diagnose the problem:

  1. Any crash reports (https://github.com/xamarin/xamarin-macios/wiki/Diagnosis#crash-reports)
  2. The device log (https://support.apple.com/en-in/guide/console/cnsl1012/mac) from when the app crashes.

@adarshchiniwar-smartq
Copy link
Author

adarshchiniwar-smartq commented Nov 7, 2024

device logs.zip

Hi,
Please find the attached device logs, The application I am trying to install is MauiSample.
Ios Binding library .csproj looks like below

`

NewBinding
NewBindingMaciOS
true


` Thanks, Adarsh

@adarshchiniwar-smartq
Copy link
Author

ApplicationOutput.zip
After the splash screen disappears it VS waits for around 1 mins and throws error saying could not attach debugger.
I have also attached application output.
Please let me know If any more info is required.

Thanks,
Adarsh

@rolfbjarne
Copy link
Member

Looks like there's a problem with FPLoggerKit.framework:

'Library not loaded: @rpath/FPLoggerKit.framework/FPLoggerKit
Referenced from: <80FED3DF-AF6C-3B97-9E89-CD35D6660176> /private/var/containers/Bundle/Application/47885F76-2BB6-445E-B16F-4DA45448532E/MauiSample.app/Frameworks/NewBinding.framework/NewBinding
Reason: tried:
'/private/var/containers/Bundle/Application/47885F76-2BB6-445E-B16F-4DA45448532E/MauiSample.app/Frameworks/FPLoggerKit.framework/FPLoggerKit' (no such file),
'/private/var/containers/Bundle/Application/47885F76-2BB6-445E-B16F-4DA45448532E/MauiSample.app/Frameworks/NewBinding.framework/Frameworks/FPLoggerKit.framework/FPLoggerKit' (code signature in '/private/var/containers/Bundle/Application/47885F76-2BB6-445E-B16F-4DA45448532E/MauiSample.app/Frameworks/NewBinding.framework/Frameworks/FPLoggerKit.framework/FPLoggerKit' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.),
'/private/var/containers/Bundle<…>'

the interesting part is the path to the framework:

MauiSample.app/Frameworks/NewBinding.framework/Frameworks/FPLoggerKit.framework/FPLoggerKit

which is not correct, it should be:

MauiSample.app/Frameworks/FPLoggerKit.framework/FPLoggerKit

I don't know where "NewBinding.framework" comes from, can you get an MSBuild binlog for a clean build?

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated and removed need-attention An issue requires our attention/response labels Nov 7, 2024
@adarshchiniwar-smartq
Copy link
Author

adarshchiniwar-smartq commented Nov 8, 2024

bindlogs.zip
Hi,

Please find the attached binlogs
I am using native introp library template to create the binding library - https://github.com/CommunityToolkit/Maui.NativeLibraryInterop
it works when we don't add any frameworks in Xcode projects.

Edit - NewBinding.Framework is the framework which additionally uses frameworks called FPLoggerKit
Thanks,
Adarsh

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Nov 8, 2024
@rolfbjarne
Copy link
Member

Ah, I see.

I think you need to follow the success case here: CommunityToolkit/Maui.NativeLibraryInterop#43 (comment)

That would basically not copy any nested frameworks into NewBinding.framework (step 3), and then you need to manually reference each of the frameworks NewBinding.framework needs as separate NativeReference items (step 4).

@rolfbjarne rolfbjarne added need-info Waiting for more information before the bug can be investigated no-auto-reply For internal use and removed need-attention An issue requires our attention/response labels Nov 8, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot removed the no-auto-reply For internal use label Nov 8, 2024
@adarshchiniwar-smartq
Copy link
Author

adarshchiniwar-smartq commented Nov 11, 2024

@rolfbjarne Thanks a lot for the help, Application launches without the crashing.
Can we please keep the thread open for 3 to 5 days ? in case if I have to discuss any doubt.

@microsoft-github-policy-service microsoft-github-policy-service bot added need-attention An issue requires our attention/response and removed need-info Waiting for more information before the bug can be investigated labels Nov 11, 2024
@adarshchiniwar-smartq
Copy link
Author

Hi,
I have added a framework called ifcckit in a framework xcproj, and I have included the same in iOS binding library as well
I am getting the below error

Please help me with this

--------------------.csproj----------------------------------------

<ItemGroup> <NLIXcodeProjectReference Include="../native/NewBinding/NewBinding.xcodeproj"> <SchemeName>NewBinding</SchemeName> <SharpieNamespace>NewBindingMaciOS</SharpieNamespace> <SharpieBind>true</SharpieBind> <!-- Metadata applicable to @(NativeReference) will be used if set, otherwise the following defaults will be used: <Kind>Framework</Kind> <SmartLink>true</SmartLink> --> </NLIXcodeProjectReference> </ItemGroup> <!-- Reference to NuGet for building bindings --> <ItemGroup> <PackageReference Include="CommunityToolkit.Maui.NativeLibraryInterop.BuildTasks" Version="0.0.1-pre1" PrivateAssets="all" /> </ItemGroup> <ItemGroup> <NativeReference Include="FPLoggerKit.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="FPAmaKit.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="FPLoggerKit.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="FPPOICore.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="FPRuaKit.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="FPTetraKit.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="iFCCCore.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> <Frameworks>FPAmaKit FPLoggerKit FPPOICore FPRuaKit FPTetraKit iFCCCore iSAF</Frameworks> </NativeReference> <NativeReference Include="iFCCKit.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="iSAF.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="RUA_MFI.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> <NativeReference Include="TemLibrary.xcframework"> <Kind>Framework</Kind> <SmartLink>False</SmartLink> <ForceLoad>True</ForceLoad> </NativeReference> </ItemGroup>
Screenshot 2024-11-12 at 6 33 48 PM

Bindlogs ios.zip

/Users/adarshchiniwar/.nuget/packages/communitytoolkit.maui.nativelibraryinterop.buildt
asks/0.0.1-pre1/tools/Common.macios.targets(5,5): Error SHRP0000: Parsing 1 header files...
/Users/adarshchiniwar/Downloads/template/macios/native/NewBinding/bin/Release/net8.0-ios/NewBindingiOS.xcarchive/Products/Library/Frameworks/NewBinding.framework/Headers/NewBinding-Swift.h:284:9: fatal error: module 'iFCCKit' not found
284 | @import iFCCKit;
| ~~~~~~~^~~~~~~

Binding...
[write] ApiDefinitions.cs
1 error generated.
Error while processing /Users/adarshchiniwar/Downloads/template/macios/native/NewBinding/bin/Release/net8.0-ios/NewBindingiOS.xcarchive/Products/Library/Frameworks/NewBinding.framework/Headers/NewBinding-Swift.h.

Done. Exiting with error code 1.
error: Clang failed to parse input and exited with code 1 (SHRP0000) (NewBinding.MaciOS.Binding)

@rolfbjarne
Copy link
Member

I'm not sure what's going on, but it seems there are some dependency calculation that goes wrong or is incomplete in Maui.NativeLibraryInterop. I would suggest filing an issue here, to see if they can help: https://github.com/CommunityToolkit/Maui.NativeLibraryInterop/issues

@adarshchiniwar-smartq
Copy link
Author

Hi @rolfbjarne,

I’ve already logged the issue but haven’t received a response yet. Could you please confirm if the following approach would work? If so, I’ll give it a try:

Create an Xcode project of type Framework.
Add all 10 third-party frameworks to the project.
Implement the required functionality using the included frameworks.
Define header files and expose the necessary functions.
Use Objective Sharpie to generate the ApiDefinitions for the header files.
Include the newly created framework along with the 10 third-party dependency frameworks as Native References in the iOS Binding Library.
Use the generated iOS Binding Library DLL and resources in the .NET MAUI project.
This approach is based on the guide provided in the following link:
https://learn.microsoft.com/en-us/previous-versions/xamarin/ios/platform/binding-swift/walkthrough

Thanks,
Adarsh

@rolfbjarne
Copy link
Member

Hi @rolfbjarne,

I’ve already logged the issue but haven’t received a response yet. Could you please confirm if the following approach would work? If so, I’ll give it a try:

Create an Xcode project of type Framework. Add all 10 third-party frameworks to the project. Implement the required functionality using the included frameworks. Define header files and expose the necessary functions. Use Objective Sharpie to generate the ApiDefinitions for the header files. Include the newly created framework along with the 10 third-party dependency frameworks as Native References in the iOS Binding Library. Use the generated iOS Binding Library DLL and resources in the .NET MAUI project. This approach is based on the guide provided in the following link: learn.microsoft.com/en-us/previous-versions/xamarin/ios/platform/binding-swift/walkthrough

Thanks, Adarsh

Yes, generally speaking that process should still work.

Note that third-party frameworks often have quirks that might need some kind of extra attention, but nothing that shouldn't be doable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
binding-projects Issue or PR that affects binding projects
Projects
None yet
Development

No branches or pull requests

2 participants