4

I'm trying to distribute a Swift Package that depends on some libraries from CocoaPods. The end goal is to be able to import a feature written in React Native into a Native iOS app using Swift Package Manager. I'm starting out with a simple example where the distributed package depends on Alamofire instead of React Native.

Publishing the package

  1. Create a framework that encapsulates the feature I which to publish. Let's call it SomeFramework. This framework depends on libraries from Cocoapods, let's say it depends on Alamofire.
  2. Archive both iPhone and Simulator version of the framework. Like this:
xcodebuild archive \
 -workspace RNFeaturePOC.xcworkspace \
 -scheme SomeFramework \
 -archivePath Archives/SomeFramework-iphoneos.xcarchive \
 -sdk iphoneos \
 BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
 SKIP_INSTALL=NO

and similarly for the iphonesimulator SDK.

  1. Bundle both archives into a XCFramework like so:
xcodebuild -create-xcframework \
 -framework Archives/SomeFramework-iphonesimulator.xcarchive/Products/Library/Frameworks/SomeFramework.framework \
 -framework Archives/SomeFramework-iphoneos.xcarchive/Products/Library/Frameworks/SomeFramework.framework \
 -output Output/SomeFramework.xcframework
  1. Publish the package as a Swift Package on GitHub, with Package file:
let package = Package(
    name: "SomeFramework",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(name: "SomeFramework", targets: ["SomeFramework"])
    ],
    dependencies: [
    ],
    targets: [
        .binaryTarget(
            name: "SomeFramework",
            path: "RNFeaturePOC/Output/SomeFramework.xcframework"
        )
    ]
)

Importing the Package

In a seperate app, let's call it ClientApp, I now add that published package as a Swift Package. It's able to find, fetch and install the package, but when I import the package in a source file of ClientApp, it giving me the following build error: Failed to build module 'SomeFramework' from its module interface; it may have been damaged or it may have triggered a bug in the Swift compiler when it was produced

It seems to me like the produces XCFramework doesn't contain all the stuff it needs to build. Also, when directly linking the framework in another app (without using Swift Package Manager), I see the same error.

I tried the same approach with a package that didn't have any CocoaPod dependencies, and was able to get all the way through to importing and running the package without any issues.

Here's an image to give you an overview of the whole process: Swift package with CocoaPods dependencies

Wiingaard
  • 4,150
  • 4
  • 35
  • 67

0 Answers0