"No such module" when using SwiftPM binaryTarget/XCFramework on dependency

I had a similar issue in one of our packages when using binary frameworks, where we had to create C target wrapper with .c and .h files, so now this C target wrapper depends on the binary target, here is an example how it needs to be structured in the package

Here is how the package manifest should look

import PackageDescription

let package = Package(
    name: "TestPackage",
    platforms: [
        .iOS(.v15),
        .macOS(.v12)
    ],
    products: [
        .library(
            name: "TestPackage",
            targets: ["TestPackage"])
    ],
    dependencies: [],
    targets: [
        .target(
            name: "TestPackage",
            dependencies: [
                "TestWrapper"
            ]
        ),
        .target(
            name: "TestWrapper",
            dependencies: ["Test"],
            path: "TestWrapper/TestWrapper"
        ),
        .binaryTarget(
            name: "Test",
            path: "Frameworks/Test.xcframework"
        )
    ],
    swiftLanguageVersions: [.v5]
)

Then add your binary framework header import to .h file in the C target wrapper

#ifndef Bridge_h
#define Bridge_h

#ifdef __OBJC__

// Add all required headers from the binary framework.
#include "Test.h"

#endif


#include <stdio.h>

#endif 

Then in your package just import the C target which will provide access to the binary package inside your package

import TestWrapper
4 Likes