In the main target add:
cd "${CODESIGNING_FOLDER_PATH}"
find ./PlugIns -type d -name Frameworks | xargs rm -rf
The problem is that adding SPM packages on multiple targets of the same project will duplicate the dependencies. The frameworks on this extension are probably on the main target so this should be enough. Otherwise use the full script below on the main target, which will deduplicate the frameworks if needed by moving them to the app.
Do NOT add this in your extension target because it will run before the framework is copied to the extension.
cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
if [[ -d "Frameworks" ]]; then
rm -fr Frameworks
fi
I ran into this problem in a project that uses Rx as a SPM package in the main target, frameworks, and extensions. If you have the same or similar problem (e.g. Firebase), you can fix it with the following script in the main target:
if ! [ "${CONFIGURATION}" == "Release" ] ; then
echo "early exit"
exit 0
fi
cd "${CODESIGNING_FOLDER_PATH}/Frameworks/"
# copy frameworks to TeamworkProjects.app/Frameworks
for framework in *; do
if [ -d "$framework" ]; then
if [ -d "${framework}/Frameworks" ]; then
echo "Moving embedded frameworks from ${framework} to ${PRODUCT_NAME}.app/Frameworks"
cp -R "${framework}/Frameworks/" .
rm -rf "${framework}/Frameworks"
fi
fi
done
# remove leftover nested frameworks
for framework in *; do
if [ -d "$framework" ]; then
if [ -d "${framework}/Frameworks" ]; then
echo "Removing embedded frameworks from ${framework} to ${PRODUCT_NAME}.app/Frameworks"
rm -rf "${framework}/Frameworks"
fi
fi
done
# Remove Frameworks from PlugIns
cd "${CODESIGNING_FOLDER_PATH}"
find ./PlugIns -type d -name Frameworks | xargs rm -rf
# codesign for Debugging on device
if [ "${CONFIGURATION}" == "Debug" ] & [ "${SDKROOT}" != *Simulator* ] ; then
echo "Code signing frameworks..."
find "${CODESIGNING_FOLDER_PATH}/Frameworks" -maxdepth 1 -name '*.framework' -print0 | while read -d $'\0' framework
do
# only sign frameworks without a signature
if ! codesign -v "${framework}"; then
codesign --force --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --preserve-metadata=identifier,entitlements --timestamp=none "${framework}"
echo "Added missing signature to '${framework}'"
fi
done
fi
Most of this script came from user pewe at forums.swift.org: Swift packages in multiple targets results in duplication of library code.
target
andEmeddded Binaries
of each target. – icodesign