简体   繁体   中英

Xamarin.iOS binding for a swift library

I am creating a binding for a swift library to be used in a xamarin project. When i consume the binding project in the ios project, I get the following error:

Dyld Error Message:
Library not loaded: @rpath/Alamofire.framework/Alamofire
Referenced from: 
/Users/USER/Library/Developer/CoreSimulator/Devices/73CDF7FB-D700-4F35- 
AB8B-DD7F7B134C1E/data/Containers/Bundle/Application/9FB74CDE-93C3- 
4EB7-9833- FA060281CE46/XXXXXXXX.iOS.app/Frameworks/MobiiiSDK.framework/MobiiiSDK
Reason: image not found

I have added https://github.com/Flash3001/Xamarin.Swift to my project to reference swift libraries.

Have set both SmartLink and ForceLink to true

I have deleted the obj and bind folders in all projects. Did a clean and rebuild too.

I would appreciate any help to fix this error.

This might not be the direct answer to your question but can definitely take you in the right direction, here is the Office UI Fabric Xamarin.iOS Swift binding project that you can use as reference, it does not use (need) the Xamarin.Swift but uses a msbuild script that uses swift-stdlib-tool which is the tool that Xcode uses to determine what swift libraries need to be bundled with your application. The script [1] needs to be added to your final app .csproj as shown here .

In your particular case it seems that you are missing MobiiiSDK.framework from your bundle.

[1]: MSBuild script to bundle Swift libraries into your Xamarin iOS Application

<PropertyGroup>
    <_SwiftySwiftMasterAfterTargets>_CodesignNativeLibraries</_SwiftySwiftMasterAfterTargets>
    <_SwiftySwiftMasterDependsOnTargets>_SwiftySwiftCopySwiftDependencies</_SwiftySwiftMasterDependsOnTargets>
    <_XcodeToolChainRelativeToSdkRoot>/../../../../../Toolchains/XcodeDefault.xctoolchain/</_XcodeToolChainRelativeToSdkRoot>
    <_TargetPlatform Condition=" '$(Platform)' == 'iPhoneSimulator' ">iphonesimulator</_TargetPlatform>
    <_TargetPlatform Condition=" '$(Platform)' == 'iPhone' ">iphoneos</_TargetPlatform>
    <_SwiftySwiftRemoteMirror Condition=" '$(Configuration)' != 'Debug' "></_SwiftySwiftRemoteMirror>
    <_SwiftySwiftRemoteMirror Condition=" '$(Configuration)' == 'Debug' ">--resource-library libswiftRemoteMirror.dylib</_SwiftySwiftRemoteMirror>
  </PropertyGroup>
  <Target Name="_SwiftySwiftMasterTarget" Condition="'$(_SwiftySwiftMasterDependsOnTargets)'!=''" AfterTargets="$(_SwiftySwiftMasterAfterTargets)" DependsOnTargets="$(_SwiftySwiftMasterDependsOnTargets);_DetectSigningIdentity" />
  <Target Name="_SwiftySwiftCopySwiftDependencies" Condition="!Exists('$(_AppBundlePath)Frameworks/libswiftCore.dylib')">
    <Message Text="Copying Swift Frameworks dependencies for $(_NativeExecutable) to the $(_AppBundlePath)Frameworks folder." />
    <Exec Condition="'$(_CodeSigningKey)' != ''" SessionId="$(BuildSessionId)" Command="$(_SdkRoot)$(_XcodeToolChainRelativeToSdkRoot)usr/bin/swift-stdlib-tool --copy --verbose --sign '$(_CodeSigningKey)' --scan-executable '$(_NativeExecutable)' --scan-folder '$(_AppBundlePath)Frameworks/' --scan-folder '$(_AppBundlePath)PlugIns/' --platform '$(_TargetPlatform)' --toolchain '$(_SdkRoot)$(_XcodeToolChainRelativeToSdkRoot)' --destination '$(_AppBundlePath)Frameworks/' $(_SwiftySwiftRemoteMirror) --unsigned-destination '$(DeviceSpecificIntermediateOutputPath)/SwiftSupport' --strip-bitcode --strip-bitcode-tool '$(_SdkRoot)$(_XcodeToolChainRelativeToSdkRoot)usr/bin/bitcode_strip' --emit-dependency-info '$(DeviceSpecificIntermediateOutputPath)/SwiftStdLibToolInputDependencies.dep'" />
    <Exec Condition="'$(_CodeSigningKey)' == ''" SessionId="$(BuildSessionId)" Command="$(_SdkRoot)$(_XcodeToolChainRelativeToSdkRoot)usr/bin/swift-stdlib-tool --copy --verbose                             --scan-executable '$(_NativeExecutable)' --scan-folder '$(_AppBundlePath)Frameworks/' --scan-folder '$(_AppBundlePath)PlugIns/' --platform '$(_TargetPlatform)' --toolchain '$(_SdkRoot)$(_XcodeToolChainRelativeToSdkRoot)' --destination '$(_AppBundlePath)Frameworks/' $(_SwiftySwiftRemoteMirror) --unsigned-destination '$(DeviceSpecificIntermediateOutputPath)/SwiftSupport' --strip-bitcode --strip-bitcode-tool '$(_SdkRoot)$(_XcodeToolChainRelativeToSdkRoot)usr/bin/bitcode_strip' --emit-dependency-info '$(DeviceSpecificIntermediateOutputPath)/SwiftStdLibToolInputDependencies.dep'" />
  </Target>
  <Target Name="_SwiftySwiftCopySwiftSupport" Condition="'$(ArchiveOnBuild)'=='true'" AfterTargets="Archive">
    <Message Text="Copying SwiftSupport folder from $(DeviceSpecificIntermediateOutputPath)/SwiftSupport to $(ArchiveDir)/SwiftSupport folder." />
    <Ditto
        SessionId="$(BuildSessionId)"
        Condition="'$(IsMacEnabled)' == 'true'"
        ToolExe="$(DittoExe)"
        ToolPath="$(DittoPath)"
        Source="$(DeviceSpecificIntermediateOutputPath)/SwiftSupport"
        Destination="$(ArchiveDir)/SwiftSupport" />
  </Target>

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM