1

I have Xamarin.iOS project and I'm trying to use Vivalnk sdk (a Swift 5 framework) in it.

I'm attempting to walk through this guide: https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough

Note that I've ignored building native library step as Swift sdk was provided with objective-c headers built-in.

So, I used an objective sharpie to generate ApiDefinitions.cs and StructsAndEnums.cs files.

Once used this command : (Objective c)

sharpie bind --sdk=iphoneos14.2 --output="XamarinApiDef" --namespace="Binding" --scope="/VivalnkSDK.framework/Headers/" "/VivalnkSDK.framework/Headers/VVBleManager.h"

and once used this : (Swift)

sharpie bind -sdk iphoneos14.2 -scope VivalnkSDK.framework/Headers/ VivalnkSDK.framework/Headers/VVBleManager.h

And finally, I used the following command's results:

sharpie bind -sdk iphoneos14.2 -scope VivalnkSDK.framework/Headers/ VivalnkSDK.framework/Headers/VivalnkSDK-swift.h

Then, I created iOS binding library, replaced these files with old ones, and set the build action according to Microsoft's document.

Then, I added Vivalnk framework to Native References, set smartlink to true, and force load to false. After a successful binding library build, I referenced this iOS binding library to my Xamarin.iOS project and use it but when I bulid Xamarin.iOS project, got 249 errors like following errors:

Could not find or use auto-linked library 'swiftFoundation' (Vivalnk) Native linking
Native linking failed, undefined symbol: nominal type descriptor for Swift.Double. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in. (MT5210) (Vivalnk)

I search a lot on the internet and also tried these:

  • Set Linker behavior to Link Framework SDKs only.
  • Install Xamarin.Swift in both projects.
  • Add this :
-/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/ -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Wl,-rpath -Wl,@executable_path/Frameworks

to Linker Flags of native reference in the iOS binding library.

Add this :

--gcc_flags -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/ -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -Wl,-rpath -Wl,@executable_path/Frameworks

in additional mtouch arguments in the executable project's iOS Build options.

I checked the location of Xcode, it is exactly there. But none of them worked for me. I tested in both Visual Studio for Mac and windows and nothing changed.

I created a sample project here which contains everything you need to reproduce build errors: https://github.com/SomayeEbrahimi/Vivalnk.iOS

Environment:

Vivalnk architecture sdk:  Arm64 
Visual Studio for mac Version: 8.8.4
Visual Studio for windows : 16.8.3
Xamarin.iOS version : 14.6.0.15
XCode Version: 12.2
Swift Version: 5

Update

If I add "Foundation" to frameworks of native reference, those errors will disappear and we will have the following error

Vivalnk.iOS/Vivalnk/error MT5209: Error: in XCode/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator/libswiftCompatibility50.a(Overrides.cpp.o),
building for iOS, but linking in object file built for iOS Simulator, for architecture arm64 (Vivalnk) Native linking
Federico Navarrete
  • 3,069
  • 5
  • 41
  • 76
Yaser Moradi
  • 3,267
  • 3
  • 24
  • 50
  • 1
    Hi, do you mean the error occurs when [Build a native library](https://learn.microsoft.com/en-us/xamarin/ios/platform/binding-swift/walkthrough#build-a-native-library)? – Junior Jiang Dec 28 '20 at 06:55
  • Swift SDK has been provided with Objective-C headers built-in, so I ignored that. You can take a look at GitHub repository which helps you reproduce build errors in Xamarin.iOS build. – Yaser Moradi Dec 28 '20 at 09:14
  • 1
    Okey, do you test it in a physical device? From errors, it seems only for *iOS Simulator, for architecture arm64 (Vivalnk) Native linking*. – Junior Jiang Dec 28 '20 at 09:34
  • Yes, I'm testing against a physical device (iPhone 6S iOS 14.3) – Yaser Moradi Dec 28 '20 at 13:02
  • 1
    Okey, you can have a check with running in a simulator. If it works, the problem should be the downloaded swift library only builds for simulator, you need to choose a library builds for simulator and physical device. – Junior Jiang Dec 29 '20 at 02:39
  • @YaserMoradi I'm facing a similar issue with an Objective-C SDK that includes some Swift bits, were you able to find a solution? – Hicham Mar 05 '22 at 18:26
  • Not a 100% guaranteed solution. I was able to make it work using specific versions of xcode / vs while I wasn't able to make the same project built by other versions – Yaser Moradi Mar 05 '22 at 20:14

0 Answers0