skip to Main Content

My project contains a Swift Package that contains a binary target. Generally, the project compiles and works properly, but the problem occurs when I try to archive the project, where I get a complier error saying No such module 'MyFramework'.
The Swift Package looks like this:

let package = Package(
    name: "MyPackage",
    platforms: [
        .iOS(.v13)
    ],
    products: [
        .library(name: "MyPackage", targets: ["MyPackage"]),
    ],
    dependencies: [
        // Product dependencies...
    ],
    targets: [
        .binaryTarget(name: "MyFramework", path: "MyFramework.xcframework"),
        .target(
             name: "MyPackage",
            dependencies: [
                "MyFramework"
                ...
            ],
            resources: [.process("Resources")]
         ),
        .testTarget(
            name: "MyPackageTests",
            dependencies: ["MyPackage"])
    ]
)

I’ve tried following many solutions, among them a proposal from the Apple Developer forums where I added the framework to the products as another library and then added the framework on the app (project / client) side, which made it archive successfully, but when I tried upload the archive to the App Store I got an error saying Found an unexpected Mach-O header code: 0x72613c21.
Right now, I am trying to follow other solutions mainly on the Swift Forums but none of them seem to work for me or be clear enough.
From what I’ve seen, this is a Swift Bug but I am wondering if there is any workaround that is sufficient for now.

Any help will be highly appreciated. Thanks in advance!

2

Answers


  1. Chosen as BEST ANSWER

    After too many hours we managed to find a (pretty ugly) workaround that archives properly.
    Basically, we need to the framework as a library to the product, like so:

    let package = Package(
        name: "MyPackage",
        platforms: [.iOS(.v13)],
        products: [
            .library(name: "MyPackage", targets: ["MyPackage"]),
            .library(name: "MyFramework", targets: ["MyFramework"]),
        ], 
        ...
        targets: [
            ...
            .binaryTarget(name: "MyFramework", path: "MyFramework.xcframework") 
        ]
    )
    

    Then link the frameworks on the project in Frameworks, Libraries and Embedded Content.
    This in for itself though isn't enough, as the project will archive but will throw the error Found an unexpected Mach-O header code: 0x72613c21 like I mentioned in the original question. In order to resolve this issue, we needed to add the following script to the Archive's Post-actions in the project's scheme:

    LOGFILE="${ARCHIVE_PATH}/static-frameworks.log"
    echo "Removing static frameworks from ${WRAPPER_NAME} archive" > $LOGFILE
    find "${ARCHIVE_PRODUCTS_PATH}/Applications/${WRAPPER_NAME}" -name '*.framework' -print0 | while IFS= read -r -d '' fm; do
        name=$(basename "${fm}" .framework)
        target="${fm}/${name}"
        echo "Checking: ${fm}" >> $LOGFILE
        if file "${target}" | grep -q "current ar archive"; then
            rm -rf "${fm}"
            echo "Removed static framework: ${fm}" >> $LOGFILE
        fi
    done
    

    Now the project archives successfully an can be uploaded to the App Store. Still obviously not an ideal solution, looking forward to hearing from Apple or for other possible solutions.


  2. Update to Xcode 12.5 for a fix.

    Much more detail and discussion here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search