1 year ago

#73696

test-img

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.

  1. Create a framework app in Xcode. enter image description here

  2. Add a swift file with below sample code. enter image description here

  3. Exclude the arm64 architecture due to the same architecture found exception the on creation of the fat file. enter image description here

  4. Add MSAL library to our framework project through the swift dependency. enter image description here enter image description here

  5. 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.

https://github.com/xamcat/xamarin-binding-swift-framework/blob/master/Swift/Scripts/build.fat.sh#L3-L14

Create Xamarin.iOS and the binding project as below.

  1. Add the MSAL_FRAMEWORK and the MSAL framework to the Native References
  2. Add the ApiDefinitions.cs to the Binding project and select ObjcBindingApiDefinition from the build action.
  3. Add the Binding project reference to the Xamarin.iOS project.
  4. Import the Binding project where it is needed
  5. Call the API

enter image description here enter image description here

Enable the Smart Link option by checking it for both the MSAL_FRAMEWORK.framework and MSAL.framework. Refer to the below screenshot. enter image description here

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.

enter image description here

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

Accepted video resources