swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.76k stars 1.35k forks source link

Error when Adding Swift Package to Cocoapods workspace which brings in framework already exists through Cocoapods. #8071

Open fangmobile opened 1 month ago

fangmobile commented 1 month ago

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

Description

When using CocoaPods and Swift Packages together. When both of them bring in the same framework, Xcode issues warnings about it. Potential runtime issues can occur too.

For example an app uses ViewRow via CocoaPods and ImageRow through SPM, both of which depend on another common library, Eureka. As a result, Eureka is added to the workspace twice.

ViewRow:

s.dependencies = {
    'Eureka' => '>= 5.0.0'
  }

ImageRow:

dependencies: [
        .package(url: "https://github.com/xmartlabs/Eureka.git", from: "5.3.5"),
    ]

Expected behavior

App builds with no warning or error.

Actual behavior

Xcode warnig:

objc[34221]: Class _TtC6Eureka7BaseRow is implemented in both /Users/user/Library/Developer/CoreSimulator/Devices/1254166F-7697-45C2-AE0A-4B3E8629A24C/data/Containers/Bundle/Application/562AAF1F-437A-4956-90BD-7682DAAA2BAD/Mixed.app/Frameworks/Eureka.framework/Eureka (0x102c0da80) and /Users/user/Library/Developer/CoreSimulator/Devices/1254166F-7697-45C2-AE0A-4B3E8629A24C/data/Containers/Bundle/Application/562AAF1F-437A-4956-90BD-7682DAAA2BAD/Mixed.app/Mixed.debug.dylib (0x1029038e8). One of the two will be used. Which one is undefined.

and 13 more of the similar warning with different class name.

Potential runtime error could happen too.

Steps to reproduce

1 create xcode app project. 2 pod init. 3 Add pod dependency. ViewRow 4 Open worksapce. App builds normal. 5 Add SPM dependency in Xcode. package(url: "https://github.com/xmartlabs/Eureka.git", from: "5.3.5") 6 Build.

Or goto https://github.com/fangmobile/SwiftXPods

Swift Package Manager version/commit hash

// swift-tools-version: 6.0

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx14.0 Darwin macos-VR7J3W3GKP 23.6.0 Darwin Kernel Version 23.6.0: Wed Jul 31 20:49:39 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6000 arm64