I have library that is a SPM package. It has one dependency.
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "ExampleLibrary",
platforms: [
.macOS(.v10_15), .iOS(.v13), .tvOS(.v13)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "ExampleLibrary",
type: .dynamic,
targets: ["ExampleLibrary"]),
],
dependencies: [
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMajor(from: "1.8.1")),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "ExampleLibrary",
dependencies: ["CryptoSwift"]),
.testTarget(
name: "ExampleLibraryTests",
dependencies: ["ExampleLibrary"]),
]
)
This library is then build an exported to binary XCFramework and distributed as another SPM package
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "ExampleSDK",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
],
products: [
.library(
name: "ExampleSDK",
targets: ["ExampleLibraryFramework"]),
],
targets: [
.binaryTarget(name: "ExampleLibraryFramework", path: "ExampleLibrary.xcframework")
]
)
when I import this package to an app for usage and use
import ExampleLibrary
I have in this line error Missing required module 'CryptoSwift'
When I import CryptoSwift in the app as another package dependency I have an error:
objc[5702]: Class _TtC11CryptoSwift15XChaCha20Worker is implemented in both [...]/ExampleLibrary (0x1016edcf0) and [...]/example.app/example (0x100611908). One of the two will be used. Which one is undefined.
Also when I add to my XCFramework Package CryptoSwift dependency it also stops showing the error but the duplicate import is the same.
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "ExampleSDK",
platforms: [
.iOS(.v13),
.macOS(.v10_15),
],
products: [
.library(
name: "ExampleSDK",
targets: ["ExampleLibraryFramework", "ExampleSDK"]),
],
dependencies: [
.package(url: "https://github.com/krzyzanowskim/CryptoSwift.git", .upToNextMajor(from: "1.8.1")),
],
targets: [
.target(name: "ExampleSDK", dependencies: ["CryptoSwift"]),
.binaryTarget(name: "ExampleLibraryFramework", path: "ExampleLibrary.xcframework")
]
)
Questions
- How can I disable exposing
CryptoSwiftfrom my library so it can be imported in the app without duplicates? I've tried using@_implementationOnly import CryptoSwiftinside my library but it did not stopped exposing it when I import another CryptoSwift in app. - How to make the app project see that this dependency is embedded inside the XCFramework. This is how XCFramework looks like inside:
