8

I want to create a Swift Package with binary targets which has sub dependencies. As the binary targets not support sub dependencies out of the box, I have created a wrapper target that depends on both the binary framework and other dependencies as described here

Package has a target called Logger. CocoaLumberjack is a dependency of Logger.

Logger I have generated as XCFramwork and hosted in a server as publicly accessible. Below I have added a screenshot of the Xcode project which I used to generate XCFramwork.

Please refer to the Package manifest file.

import PackageDescription

let package = Package(
    name: "spmpoc",
    products: [
        .library(
            name: "Logger",
            targets: ["LoggerTarget"]),
    ],
    dependencies: [
        .package(
            name: "CocoaLumberjack",
            url: "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
            from: "3.6.1"),
    ],
    targets: [
        .target(
              name: "LoggerTarget",
              dependencies: [.target(name: "LoggerWrapper",
                                     condition: .when(platforms: [.iOS]))]
            ),
        .target(
              name: "LoggerWrapper",
              dependencies: [
                .target(name: "Logger", condition: .when(platforms: [.iOS])),
                .product(name: "CocoaLumberjack", package: "CocoaLumberjack")
              ]
            ),
        .binaryTarget(name: "Logger", url: "https://mypath.com/Logger.xcframework.zip", checksum: "mychecksum")
    ]
)

I am able to add Swift package via Swift Package Manager, but When I try to import Logger module build error occured as ..../Logger.framework/Modules/Logger.swiftmodule/arm64-apple-ios.swiftinterface:4:8: No such module 'CocoaLumberjack'

Could someone please help me to figure out what could be the issue here?

Error enter image description here

XCFramwork code snapshot for reference enter image description here

Update:

I have change import to @_implementationOnly import in Logger.swift. Now in the generated .swiftinterface files does not contains the "import CocoaLumberjack" hence, compile error went away. However, app crashing because it is still looking for CocoaLumberjack.framework but its not available. '.../Library/Developer/Xcode/DerivedData/TestSPMApp-gfbagjtzjrrkjuathrrienvklwxs/Build/Products/Debug-iphonesimulator/CocoaLumberjack.framework/CocoaLumberjack' (no such file) CocoaLumberJack added to Logger framework as a pod dependency. It seems, inside the Pods-Logger.xcconfig file it is referring to CocoaLumberjack.framework. I believe this causes the issue now.

enter image description here

4
  • try this this answer Commented Apr 11, 2022 at 9:11
  • @Mr.SwiftOak Thanks for the input. I had went through the answer and I re-look in to my XCFramwork generation project as well. It seems frameworkes linked correctly there. I had updated my question with XCframework part as well. Commented Apr 11, 2022 at 9:24
  • Try also checking if it is not problem with arm64 simulator , as here Commented Apr 11, 2022 at 10:55
  • In debug mode it has set to Build Active Architecture Only. I tried to build with real device as well, same issue there. I am really not sure if this is due to some misconfiguration in Package.swift Commented Apr 12, 2022 at 3:16

1 Answer 1

2

I think the real issue here is that the dependencies don't need to be a part of your modules's public interface. You would need to replace all instances of import for the dependencies in your code to @_implementationOnly import

E.g.

@_implementationOnly import CocoaLumberjack

You can read more about @_implementationOnly here

Sign up to request clarification or add additional context in comments.

12 Comments

Though compilation error went away, now app crashing because it is still looking for CocoaLumberjack.framework but its not available. Any idea? '.../Library/Developer/Xcode/DerivedData/TestSPMApp-gfbagjtzjrrkjuathrrienvklwxs/Build/Products/Debug-iphonesimulator/CocoaLumberjack.framework/CocoaLumberjack' (no such file),
CocoaLumberJack added to Logger framework as a pod dependency. It seems, inside the Pods-Logger.xcconfig file it is refering to CocoaLumberjack.framework. I believe this causes the issue now. FRAMEWORK_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/CocoaLumberjack" GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1 HEADER_SEARCH_PATHS = $(inherited) "${PODS_CONFIGURATION_BUILD_DIR}/CocoaLumberjack/CocoaLumberjack.framework/Headers"
I think so too, because it works perfectly if I have the dependency added through SPM in the main framework target
I also tried removing Pods-Logger.framework from the Link Binary Libraries of main project. And then generated the Xcframework. Issue still persists. Not sure from where these linker headers coming from :(
I am having exact same issue. Do you have any idea how to resolve this problem?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.