0
votes

Created a Swift Package (// swift-tools-version:5.3.0) for an XCFramework. The package has dependencies on 4 other Swift packages (2 of them using swift-tools-version < 5 and 2 are >= 5.0). It builds and runs in the project's Demo app target. The generated XCFramework copied into a Swift Package repo and hosted on GitHub.

I then create a new project and the Swift Package can be successfully imported into it thru SPM. The dependencies are also imported.

When building the new project, my framework fails to compile due to an error in my framework's generated .swiftinterface file, 'XMLIndexerDeserializable' is not a member type of 'SWXMLHash': 'XMLIndexerDeserializable' is not a member type of 'SWXMLHash'

Can anyone shed some light on this failure? Not sure if it an issue with my packaged framework, a config issue with the new project that imports it, or an error due to the difference in the Swift tools version of the dependencies.

Some Background Details On My Config and Process

My Swift Package config:

// swift-tools-version:5.3.0
import PackageDescription
let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v9)
    ],
    products: [
        .library(
            name: "MyPackage", 
            targets: ["MyPackage"])
    ],
    dependencies: [
        .package(name: "CryptoSwift", url: "https://github.com/krzyzanowskim/CryptoSwift", .upToNextMinor(from: "1.2.0")),
        .package(name: "Alamofire", url: "https://github.com/Alamofire/Alamofire", .upToNextMinor(from: "4.8.2")),
        .package(name: "AEXML", url: "https://github.com/tadija/AEXML", .upToNextMinor(from: "4.4.0")),
        .package(name: "SWXMLHash", url: "https://github.com/drmohundro/SWXMLHash", .upToNextMinor(from: "4.9.0"))
    ],
    targets: [
        .binaryTarget(
            name: "MyPackage",
            path: "MyPackage.xcframework")
    ]
)

Watched the WWDC 2019 and 2020 sessions on building XCFrameworks/binaries for SPM, along with other various tutorials. Used the following sh script to build the XCFramework that would be used for my hosted Swift Package:

xcodebuild archive \
  -scheme MyPackage \
  -sdk iphoneos \
  -archivePath "./XCFrameworkArchives/ios_devices.xcarchive" \
  BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
  SKIP_INSTALL=NO
  
xcodebuild archive \
  -scheme MyPackage \
  -sdk iphonesimulator \
  -archivePath "./XCFrameworkArchives/ios_simulators.xcarchive" \
  BUILD_LIBRARY_FOR_DISTRIBUTION=YES \
  SKIP_INSTALL=NO

xcodebuild -create-xcframework \
  -framework ./XCFrameworkArchives/ios_devices.xcarchive/Products/Library/Frameworks/MyPackage.framework \
  -framework ./XCFrameworkArchives/ios_simulators.xcarchive/Products/Library/Frameworks/MyPackage.framework \
  -output ./XCFrameworkArchives/MyPackage.xcframework

The XCFramework is copied into my Swift Package repo, pushed up to GitHub and tagged.

I then created a new project, used SPM to add a dependency and pulled in MyPackage along with it's dependencies.

Add code to import MyPackage and make use of it. Attempt to build the project throws the compile error that lead me to ask for help. If you can help and need more info, happy clarify and provide more info if I can.

1
Have you managed to solve this ? I am running into the same problem. - Guy Brooker
This is probably related to this SO question and this post in App Developer Forums. - gcharita
thanks, @gcharita - i experienced the same. after reading through those links, it gives me some comfort knowing others are also manually editing the .swiftinterface files. - knarf

1 Answers

0
votes

I manually edited the .swiftinterface files generated in the XCFramework for both the device and simulator versions. I simply replaced all occurrences of the framework's name from those files. So changing, SWXMLHash.XMLIndexerDeserializable -> XMLIndexerDeserializable solved the issue for me.

Also, look at the latest comments to my question, this looks like a known issue. Going through some of those links and bug issues, my solution common, but is not the "recommended" solution. Recommendation is to not name your framework the same as the classes within. In my situation, it is a Swift package dependency I imported, so I don't have control over that.