Sharing a Resources.bundle bundle with a Binary Target on Swift Package Manager

273 Views Asked by At

I'm trying to distribute an XCFramework for some internal iOS apps using Swift Package Manager. This is a third-party library that constitutes:

  • The one XCFramework
  • A Resources.bundle file

The SPM File compiles correctly and is embedded into my app, but when I try to use this framework it fails to load resources from this bundle.

Package.swift

import PackageDescription

let package = Package(
    name: "InternalZoom",
    platforms: [
        .iOS(.v12),
    ],
    products: [
        .library(
            name: "InternalZoom",
            targets: ["MobileRTC"]),
    ],
    targets: [
        .binaryTarget(name: "MobileRTC",
                      path: "MobileRTC.xcframework.zip"),
    ]
)

The file structure is:

  • iOS Zoom
    • README
    • Package
    • Sources
      • MobileRTCResources
        • Bunch of files...
      • InternalZoom InternalZoom.swift MobileRTC.xcframework.zip

I though these resources would be bundled automatically with the framework, but it looks like they don't and as such, when the framework tries to access them, it crashes.

1

There are 1 best solutions below

0
On

It sounds like you're having one of those mysterious moments where your SPM package's resources don't want to behave as they should. Let's unravel this mystery together!

First, let's take a look at your package structure. It looks like you configured everything correctly in the Package.swift file. Creating your SPM package looks like a work of art, a true masterpiece!

Now, about those features that don't want to be friends with the package... Sometimes SPM can be a little stubborn, but don't worry, we have some tips for you:

Make sure that the MobileRTC.xcframework.zip file is actually in the specified location and has not hidden in some secret corner. Sometimes they're like those items you lost in the mess in your room.

Check resource access permissions. They are like VIPs, they need special access. Make sure the SPM has the keys to open the door and access these resources.

Check that the directory structure within your MobileRTC.xcframework.zip file is correct. Sometimes a mistake in folder organization can cause resources to get lost.

And of course, always keep a close eye on the error log. He can be like a detective, revealing clues about what's going wrong.

If you follow these tips and are still having trouble, don't hesitate to share more details. I'm here to help solve this mystery and make your resources behave like champions!