Closed Lucasvor closed 1 month ago
This happens due to a bug, which we've already fixed, but unfortunately it's not released yet.
In the meantime, you can add this to your binding project file:
<PropertyGroup>
<NoBindingEmbedding>false</NoBindingEmbedding>
</PropertyGroup>
However, I noticed that you're using a static library, and that will eventually run into other problems: it doesn't work in the iOS arm64 simulator (because a static library can only contain a single slice of code for each architecture, and the "arm64" slice in the static library is already used up by the device version of "arm64").
The fix is to create an .xcframework bundleinstead of a .a file, and reference that in the project file instead. There are plenty of tutorials online for how to create .xcframeworks, but here's Apple's documentation as a starting point: https://developer.apple.com/documentation/xcode/creating-a-multi-platform-binary-framework-bundle
Thank you for the quick response @rolfbjarne , do you know if I can get it to work with an emulator in other versions? For example, .Net 7 or .Net 6, because it worked in Xamarin :(. I tried the Slim Bindings approach and it worked well, but I didn't want to have to recreate all the methods of the library that are necessary for my application's use.
Thank you for the quick response @rolfbjarne , do you know if I can get it to work with an emulator in other versions? For example, .Net 7 or .Net 6, because it worked in Xamarin :(. I tried the Slim Bindings approach and it worked well, but I didn't want to have to recreate all the methods of the library that are necessary for my application's use.
This workaround:
<PropertyGroup>
<NoBindingEmbedding>false</NoBindingEmbedding>
</PropertyGroup>
should work in .NET 6 and 7 as well.
The problem with the arm64 ios simulator still remains though, but you can choose to use the x64 simulator instead.
Description
Hi, I am trying to create a wrapper for a private iOS library. I have the file with the '.a' extension and its headers. This library was working normally, but when I bind this library to .NET MAUI, the build succeeds. However, when using it in a .NET MAUI project, it returns the following error: 'Could not create a native instance of the type 'LibTest.EmbeddedSdk': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.' I have already tried with the ObjCRuntime.Class.ThrowOnInitFailure = false option, but when executing the methods, it always returns with a default value. Could you help me with this?
Steps to Reproduce
Expected Behavior
When executing the method: 'value.Init(data)' it should return an int value different from 0 in the MainPage.xaml.cs
Actual Behavior
Return an int value different from 0 and not the erro the type 'LibTest.EmbeddedSdk'
Environment
Environment
Visual Studio Community 2022 for Mac Version 17.6.12 (build 410) Installation UUID: 76a6c7e6-4d90-439b-9dc6-d81f89ad18fc 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.300/Sdks SDK Versions: 8.0.300 7.0.316 6.0.422 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 8.0.5 7.0.19 6.0.30 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Xamarin.Android Version: 13.2.2.0 (Visual Studio Community) Commit: xamarin-android/d17-5/45b0e14 Android SDK: /Users/lucasvor/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 34.0.3 SDK Build Tools Version: 32.0.0 Build Information: Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@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-05-09 04:36:12 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2024-05-09 04:36:12 UTC Apple Developer Tools Xcode: 15.2 22503 Build: 15C500b Xamarin.Mac Not Installed Xamarin.iOS Version: 16.4.0.23 Visual Studio Community Hash: 9defd91b3 Branch: xcode14.3 Build date: 2023-10-23 16:15:00-0400 Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2024-05-09 04:36:07 UTC Build Information Release ID: 1706120410 Git revision: 2f8e0518dd80a933901821bac53f7398d4b61c0f Build date: 2024-05-09 04:34:23+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 13.6.3 Darwin 22.6.0 Darwin Kernel Version 22.6.0 Tue Nov 7 21:42:27 PST 2023 root:xnu-8796.141.3.702.9~2/RELEASE_ARM64_T8103 arm64Visual Studio for MAC
``` ```Build Logs
Example Project (If Possible)
Error:
Anyone can help with this?