# Xcode / SPM integration issue—Xcode bundles frameworks into Swift Package frameworks that shouldn't have them

**URL:** <https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119>\
**Category:** Using Swift\
**Tags:** packagemanager\
**Created:** [June 30, 2021, 6:07am UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119 "2021-06-30T06:07:38Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![1oo7](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/1oo7/32/17598_2.png) [@1oo7](https://forums.swift.org/u/1oo7)\
**Post date:** [June 30, 2021, 6:07am UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/1 "2021-06-30T06:07:38Z")

</div>

Xcode 12.5 added the ability for Xcode to automatically decide whether to use `.dynamic` or `.static` for the product type for a given Swift package when it builds it, based on whether it's used in multiple places or only in one place.

So I tried removing `.dynamic` throughout our app's 50+ local Swift packages. Afterwards, the app builds and runs fine.

However when trying to submit to the app store (test flight upload), we are getting rejected due to the fact that Xcode has now bundled every package dependency of a package into that package's framework's `Frameworks` folder, such that now there are 3, 4, and even 5 copies of each Swift package build product bundled in the app, nested inside of all the other frameworks and packages.

So for example, with a PackageA that's depended on by PackageB, that's depended on by PackageC, etc., previously when we manually specified ".dynamic," the app would have a directory structure like this:

```swift
App/
    Frameworks/
        PackageA.framework/
        PackageB.framework
        PackageC.framework
        XcodeProjectA.framework
        XcodeProjectB.framework
        XcodeProjectC.framework

```

However after removing "type: .dynamic" and letting Xcode infer, now Xcode builds an app with the following structure which gets rejected by the App Store for having duplicate bundles and Framework folders where they don't belong:

```swift
App/
    Frameworks/
        PackageA_3357E3B0B2AD110B_PackageProduct.framework/
        PackageB_AF8320FD902BA919_PackageProduct.framework/
            Frameworks/
                PackageA_3357E3B0B2AD110B_PackageProduct.framework/
        PackageC_182819ADFA392304_PackageProduct.framework/
            Frameworks/
                PackageA_3357E3B0B2AD110B_PackageProduct.framework/
                PackageB_AF8320FD902BA919_PackageProduct.framework/
        XcodeProjectA.framework
            Frameworks/
                PackageA_3357E3B0B2AD110B_PackageProduct.framework/
                PackageB_AF8320FD902BA919_PackageProduct.framework/
                PackageC_182819ADFA392304_PackageProduct.framework/
        XcodeProjectB.framework
            Frameworks/
                PackageA_3357E3B0B2AD110B_PackageProduct.framework/
        XcodeProjectC.framework
            Frameworks/
                PackageA_3357E3B0B2AD110B_PackageProduct.framework/
                PackageB_AF8320FD902BA919_PackageProduct.framework/
                PackageC_182819ADFA392304_PackageProduct.framework/

```

etc. etc. ... leading to there being many copies of the same framework embedded in the app.

However we don't have any "embed frameworks" build phases that should be responsible for this happening. And I don't see any way to force or compel Xcode not to bundle all these extra frameworks into the app.

I realize this isn't an Xcode support forum, but also, I don't know whether this is an Xcode bug or an SPM bug. Either way, I'm hoping maybe someone here knows why this would be happening, and if so, how to fix it.

BTW I did google extensively to try to find a solution, but no dice. I'm guessing my org is the only one actually trying to use SPM for locally-declared projects like this?

... Thanks...

---

<div class="post-metadata">

**Author:** ![joeboyscout04](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/joeboyscout04/32/19671_2.png) [@joeboyscout04](https://forums.swift.org/u/joeboyscout04)\
**Post date:** [September 19, 2021, 6:39pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/2 "2021-09-19T18:39:56Z")

</div>

You’re definitely not the only one. We are struggling with the same thing in our setup as well. Using Xcode 13 doesn’t seem to help either, it’s the same behavior you described.

---

<div class="post-metadata">

**Author:** ![surajbarkale](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/surajbarkale/32/17151_2.png) [@surajbarkale](https://forums.swift.org/u/surajbarkale)\
**Post date:** [September 19, 2021, 11:08pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/3 "2021-09-19T23:08:34Z")

</div>

Create a workspace like this:

```swift
Workspace/
    App/
    AppFrameworks/
      Package.swift

```

The App should only depend on the `AppFramework` with all dependencies listed in `Package.swift`. Make sure the targets within `AppFramework` are static. This somehow forces XCode to eliminate all of the duplicates.

---

<div class="post-metadata">

**Author:** ![weichsel](https://avatars.discourse-cdn.com/v4/letter/w/7feea3/32.png) [@weichsel](https://forums.swift.org/u/weichsel)\
**Post date:** [September 20, 2021, 6:32pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/4 "2021-09-20T18:32:35Z")

</div>

We are facing a very similar problem but with Extension targets.  
Despite having "Do not embed" configured, Xcode embeds frameworks built from Swift packages into extension bundles.

Our setup is as follows:

- 📁 Workspace
  - 🔨 App Project
    - 🎯 App Target
    - 🎯 Extension Target

  - 🧰 Framework Project
  - 📦 Swift Package (`libaryType: .dynamic`)

The app target uses the framework ("Link and Embed") and the Swift Package ("Link and Embed"). It also embeds the extension.  
The extension uses the Framework ("Do not Embed") and the Swift Package ("Do not Embed").  
The framework uses the Swift Package ("Do not Embed").  
The Swift Package is a "leaf" dependency.

When building and running the app target, everything works as expected but when trying to upload the app to App Store Connect, we are get multiple ITMS errors referring to the extension. (ITMS-90206: "Invalid Bundle. The bundle contains invalid file 'Framework'", ITMS-90205: "Invalid Bundle. The bundle contains disallowed nested frameworks.", ITMS-90685: "CFBundleIdentifier Collision")

When inspecting the Contents of our .appex, it contains a .framework bundle under /Frameworks.  
I double checked all involved build phases to ensure that no "Copy" phase is placing the SPM framework in anything except the main App Target.  
When investigating the build output, I can find the (unwanted) embed step:

```swift
PBXCp /BuildProductsPath/Release-iphoneos/SPMBased.framework /UninstalledProducts/iphoneos/Extension.appex/Frameworks/SPMBased.framework (in target 'Intents Extension' from project 'for iOS')
    cd ~/Projects/App
    builtin-copy -resolve-src-symlinks /BuildProductsPath/Release-iphoneos/SPMBased.framework /UninstalledProducts/iphoneos/Extension.appex/Frameworks

```

By manually removing the /Frameworks folder, the ITMS errors go away - but this doesn't sound like the correct solution to this problem. Does anyone have a more elegant workaround? Or an idea why Xcode thinks it has to embed the SPM package products into the extension?

> [@surajbarkale](#):
>
> The App should only depend on the `AppFramework` with all dependencies listed in `Package.swift` . Make sure the targets within `AppFramework` are static. This somehow forces XCode to eliminate all of the duplicates.

This would lead to duplicate symbol errors when statically linking the Swift package in e.g. an app target that links a framework which also (statically) links the same Swift package.

---

<div class="post-metadata">

**Author:** ![1oo7](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/1oo7/32/17598_2.png) [@1oo7](https://forums.swift.org/u/1oo7)\
**Post date:** [September 20, 2021, 7:07pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/5 "2021-09-20T19:07:33Z")

</div>

It's hard to believe that Apple lets this kind of thing into production software.

---

<div class="post-metadata">

**Author:** ![hurriedSloth](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/hurriedsloth/32/20026_2.png) [@hurriedSloth](https://forums.swift.org/u/hurriedSloth)\
**Post date:** [October 25, 2021, 1:30pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/6 "2021-10-25T13:30:47Z")

</div>

We are facing the same issue in our project. We have a spm-integration branch but can't merge because we can't upload on TestFlight. We stick with Cocoapods for the time being but will be nice to know more about this

---

<div class="post-metadata">

**Author:** ![MainasuK](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mainasuk/32/5181_2.png) [@MainasuK](https://forums.swift.org/u/MainasuK)\
**Post date:** [December 8, 2021, 6:41pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/7 "2021-12-08T18:41:36Z")

</div>

I try a workaround likes this:

Local Package \<- one library product with N targets  
Framework \<- Local Package [static] (Do not embed)  
App \<- Framework (Embed & Sign)  
Extension \<- Framework (Do not embed)

The Xcode warning ITMS-90685: "CFBundleIdentifier Collision". Set the [DISABLE\_DIAMOND\_PROBLEM\_DIAGNOSTIC](https://github.com/kishikawakatsumi/KeychainAccess/issues/472#issuecomment-611278956) to YES fix it.

And I get the same [result](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/4) from weichsel. The app warning this when launching :

`objc[33528]: ### is implemented in both ### (0x108c05868) and ### (0x103acd578). One of the two will be used. Which one is undefined.`

However, the app could be uploaded to App Store.

* * *

I have seen lots of discussions in the forum about this issue. But The Xcode 13.2 RC still does not fix it.

---

<div class="post-metadata">

**Author:** ![Mordil](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mordil/32/5840_2.png) [@Mordil](https://forums.swift.org/u/Mordil)\
**Post date:** [December 9, 2021, 7:49pm UTC](https://forums.swift.org/t/xcode-spm-integration-issue-xcode-bundles-frameworks-into-swift-package-frameworks-that-shouldnt-have-them/50119/8 "2021-12-09T19:49:27Z")

</div>

To get around this issue, I run a custom script as the last build phase in my app project - as reported in [Swift Packages in multiple targets results in “This will result in duplication of library code.” errors - #67 by pewe](https://forums.swift.org/t/swift-packages-in-multiple-targets-results-in-this-will-result-in-duplication-of-library-code-errors/34892/67)
