Swift Packages in multiple targets results in “This will result in duplication of library code.” errors

I think it would help to write feedback assistant and/or bug reports for SwiftPM and sharing them here and also if there is no thread about it making an appropriately tagged thread on Apple Dev Forums (always tagging the bug report reference number). If you have already reported this bug, please post it and others duping it will help raise its priority.

I was more than happy to report the following SPM issues:

  • App with a local Swift Packages sometimes can't be built if Thread Sanitizer or Undefined Behavior Sanitizer are on FB9217731
  • Bitcode bundle cannot be generated for app in release config with locally-declared dynamic library Swift Package targets if Deployment Postprocessing is on FB8956614
  • Swift Package Manager dependency on XCFramework fails due to Swift compiler version FB9028470
  • Remote swift package dependencies sometimes fail to resolve and take too long to resolve FB8944736 (they said potential fix in Xcode 12.5 but Google Firebase still takes 15 minutes to go from pasting the URL into the "Add Swift Package" dialog to the screen where you get to select which package products to depend on—and then another 15 minutes after that to deep clone the whole repo—and then another 15 minutes anytime a new employee clones our repo and tries to open it in Xcode or a new CI node spins up that doesn't have the ~800MB deep git clone of all of Firebase's repos and all of its dependencies' repos)
  • "Unexpected Duplicate Tasks" bug in Xcode FB9005461 (they said potential fix in Xcode 12.5 however it wasn't fixed, it was made much worse as described in my post above, because rather than giving you an error it just goes ahead and builds tons of frameworks into your app and it doesn't fail until you try to submit to the app store!)
  • Xcode Previews fail when using a dynamic Swift Package library that's not embedded in a framework FB8955594
  • @testable import doesn't work in Swift packages when using an Xcode configuration with a name other than "Debug" (e.g. a configuration named "Testing" maps to SPM's "Release" configuration which has @testable import disabled) FB8914293
  • Xcode fails to install xcappdata to simulator when running tests FB9070373 (OK it's not an SPM issue but this bug has been in Xcode ever since version 6.0... just so you realize what kind of operation we're dealing with)

Considering that the framework duplication bug is really just a failure caused by 12.5's "fix" for the "Unexpected Duplicate Tasks" bug, I went ahead and just updated FB9005461 with the details of how the removal of ".dynamic" from the package descriptions causes Xcode to now auto-embed every package as a framework into every other framework or package-framework that links to it, leading to app store submission failures.

Apple should open-source Xcode. It would be less work for people like you and I to actually just fix all these bugs ourselves and PR them to Xcode, rather than to constantly be creating sample projects to reproduce bugs and submitting them to a Feedback Assistant queue that advances at the rate of continental drift and half the time when a fix finally trickles down, it not only doesn't solve the problem, but actually makes it worse...

6 Likes

@ferologics are you able to run on a physical device using that script?

Yes! we use this workaround to submit the app for our TestFlight testers. Without it we get a lot of errors about duplicate symbols during the upload of the binary...

fyi we're using this improved version of the script in production now:

movedFrameworks=()
        cd "${CODESIGNING_FOLDER_PATH}/Frameworks/"
        for framework in *; do
            if [ -d "$framework" ]; then
                if [ -d "${framework}/Frameworks" ]; then
                    echo "Moving nested frameworks from ${framework}/Frameworks/ to ${PRODUCT_NAME}.app/Frameworks/"
        
                    cd "${framework}/Frameworks/"
                    for nestedFramework in *; do
                        echo "- nested: ${nestedFramework}"
                        movedFrameworks+=("${nestedFramework}")
                    done
                    cd ..
                    cd ..
        
                    cp -R "${framework}/Frameworks/" .
                    rm -rf "${framework}/Frameworks"
                fi
            fi
        done
        
        if [ "${CONFIGURATION}" == "Debug" ] & [ "${PLATFORM_NAME}" != "iphonesimulator" ] ; then
            for movedFramework in "${movedFrameworks[@]}"
            do
                codesign --force --deep --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements --timestamp=none "${movedFramework}"
            done
        else
            echo "Info: CODESIGNING is only needed for Debug on device (will be re-signed anyway when archiving) "
        fi
1 Like

thanks a ton for this, the script fixed my issue as well

Terms of Service

Privacy Policy

Cookie Policy