1 year ago
#73696
![test-img](https://lh6.googleusercontent.com/-6hF8ufmB72I/AAAAAAAAAAI/AAAAAAAAAHA/8gic1peo6Rs/photo.jpg?sz=256)
Ramesh Annadurai
Unable to run the Xamarin.iOS app when we use third party library in Xamarin binding project
We are working on a Xamarin.iOS project which consumes the MSAL library for authentication purposes. Everything works fine in MSAL except the following one.
User credentials are not getting cleared during the subsequent login. It automatically logging-in to the app without even entering the password. Refer to the below link for more info about the issue.
MSAL sign out does not appear to clear cache
After communicating with Microsoft we came to know that this feature is available only on the Native MSAL library. To rectify this issue we have planned to create a binding project (Which will hold all the boilerplate code related to the MSAL) and use it in our Xamarin.iOS app. So that our app can communicate with the MSAL through the binding project and clear the cache completely on logout. But our app is not running with the binding project when we include the MSAL library in the static project (iOS framework app). It is not showing any error or exception while trying to run our app, it just stops without any logs after the completion of compilation.
Steps that we have followed to create the binding project.
Exclude the arm64 architecture due to the same architecture found exception the on creation of the fat file.
Add MSAL library to our framework project through the swift dependency.
After completing the above steps followed the below commands to build a fat library for a given Xcode project (framework).
Build iOS framework for simulator and device
For iphonesimulator14.2
xcodebuild -sdk iphonesimulator14.2 -project "MSAL_FRAMEWORK.xcodeproj" -configuration Release
For iphoneos14.2
xcodebuild -sdk iphoneos14.2 -project "MSAL_FRAMEWORK.xcodeproj" -configuration Release
Copy one build as a fat framework.
cp -R "Release-iphoneos" "Release-fat"
Combine modules from another build with the fat framework modules.
cp -R "Release-iphonesimulator/MSAL_FRAMEWORK.framework/Modules/MSAL_FRAMEWORK.swiftmodule/" "Release-fat/MSAL_FRAMEWORK.framework/Modules/MSAL_FRAMEWORK.swiftmodule/"
Combine iphoneos + iphonesimulator configuration as fat libraries.
lipo -create -output "Release-fat/MSAL_FRAMEWORK.framework/MSAL_FRAMEWORK" "Release-iphoneos/MSAL_FRAMEWORK.framework/MSAL_FRAMEWORK" "Release-iphonesimulator/MSAL_FRAMEWORK.framework/MSAL_FRAMEWORK"
Verify the created fat file.
lipo -info "Release-fat/MSAL_FRAMEWORK.framework/MSAL_FRAMEWORK"
Should receive the following message on success: Architectures in the fat file: Release-fat/MSAL_FRAMEWORK.framework/MSAL_FRAMEWORK are: x86_64 arm64
Generating binding API definition and structs.
sharpie bind --sdk=iphoneos14.2 --output="XamarinApiDef" --namespace="Binding" --scope="Release-fat/MSAL_FRAMEWORK.framework/Headers/" "Release-fat/MSAL_FRAMEWORK.framework/Headers/MSAL_FRAMEWORK-Swift.h"
Alternatively, we can use the below script to generate the fat file.
Create Xamarin.iOS and the binding project as below.
- Add the MSAL_FRAMEWORK and the MSAL framework to the Native References
- Add the ApiDefinitions.cs to the Binding project and select ObjcBindingApiDefinition from the build action.
- Add the Binding project reference to the Xamarin.iOS project.
- Import the Binding project where it is needed
- Call the API
Enable the Smart Link option by checking it for both the MSAL_FRAMEWORK.framework and MSAL.framework. Refer to the below screenshot.
Compile and run the app. There is no issue while compiling the solution, but when we run the app it just shows as waiting for the debugger to connect to ... and stop without any intimation.
Note: We can run the app by removing the MSAL.framework from Native References and removing the MSAL lib from Swift the dependency in the framework app.
Thanks in advance.
ios
xcode
xamarin-binding
0 Answers
Your Answer