Distribute Universal framework written in Swift
Asked Answered
I

1

7

I'm facing the issue with distributing compiled swift framework. My framework heavily relies on the libxml2 dynamic library. In order to avoid issues with Swift module compatibility, I've set build flag BUILD_LIBRARY_FOR_DISTRIBUTION = YES.

So I've used Xcode 11.3 Swift v5.1.3 to build my framework. I've integrated it into the Demo.app project. As being expected Demo.app works fine in Xcode 11.3.

However, I have another error trying to build Demo.app in Xcode 11.0 Swift 5.1. I've got the error:

#import "libxml/HTMLparser.h"
        ^
/Applications/Xcode_11.0.app/Contents/Developer/Platforms/AppleTVSimulator.platform/Developer/SDKs/AppleTVSimulator13.0.sdk/usr/include/libxml2/libxml/HTMLparser.h:15:10: error: 'libxml/xmlversion.h' file not found
#include <libxml/xmlversion.h>
         ^
/.../DemoApp/ThirdParty/testXML.framework/Modules/testXML.swiftmodule/x86_64-apple-tvos-simulator.swiftinterface:6:8: error: could not build Objective-C module 'libxml2'
import libxml2
       ^
/.../DemoApp/AppDelegate.swift:11:8: error: failed to load module 'testXML'
import testXML

Here is the repo with both framework and app projects.

I'm using both Xcode version on the same Mac.

Intricacy answered 17/12, 2019 at 13:33 Comment(3)
Is it important to you to be able to build on an older version if the new version works correctly? Am I misreading the question?Shortage
@TofuWarrior: let me rephrase it: it's important to me to distribute binary built on a latest swift version which is compatible with elder swift versions. Eg. built with swift 5.1.3 but compatible with 5.0.Intricacy
@AliaksandrB. Were you able to fix this? I am stuck with the same issue :(Civilly
H
0

Your project runs fine on my Xcode 11.3 tvOS simulator. However there's something I've noticed. The framework you built only contains x86_64 architectures (simulator only), it won't work on physical devices.

For Xcode before 11.3 it seems like you need to add $(SDKROOT)/usr/include/libxml2 and ${SRCROOT}/libxml2 to Build Settings. That fixed the issue for me on Xcode 11.2.1

Hand answered 9/1, 2020 at 7:51 Comment(3)
Thanks for the response. I didn't create a fat framework, because it's just a demo. It works for me on Xcode 11.3 also, but it doesn't on earlier versions like 11.0Intricacy
I reproduced and fixed your issue, please try on your sideDoud
Still doesn't work for me, could you please send me a link to the fixed Demo project? ThanksIntricacy

© 2022 - 2024 — McMap. All rights reserved.