Last active
October 20, 2023 14:10
-
-
Save kenthumphries/cf04683184217c7331f9c213c556c65a to your computer and use it in GitHub Desktop.
Script to be called as part of an Xcode Run Script build phase. This will ensure that script Input File is copied (and code signed) to script Output File.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# This script embeds (and codesigns) a framework within an iOS app binary, but only when the configuration is Debug. | |
# It must be called from, or copied into an Xcode Run Script build phase with following setup: | |
# Input Files: | |
# - Path to framework within project folder (source path) | |
# - For example: $(SRCROOT)/ThirdPartyFrameworks/SimulatorStatusMagiciOS.framework | |
# Output Files: | |
# - Desired path to framework within ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH} (destination path) | |
# - For example: ${BUILT_PRODUCTS_DIR}/${FRAMEWORKS_FOLDER_PATH}/SimulatorStatusMagiciOS.framework | |
# | |
# For explanation of Input & Output Files, check out: https://indiestack.com/2014/12/speeding-up-custom-script-phases/ | |
# This script adapted from: https://stackoverflow.com/a/40484337/9051514 (thanks Ricardo Duarte!) | |
if [[ -z ${SCRIPT_INPUT_FILE_0} || -z ${SCRIPT_OUTPUT_FILE_0} ]]; then | |
echo "This Xcode Run Script build phase must be configured with Input & Output Files" | |
exit 1 | |
fi | |
echo "Embed ${SCRIPT_INPUT_FILE_0}" | |
if [[ $CONFIGURATION == 'Debug' ]]; then | |
FRAMEWORK_SOURCE=${SCRIPT_INPUT_FILE_0} | |
FRAMEWORK_DESTINATION=${SCRIPT_OUTPUT_FILE_0} | |
DESTINATION_FOLDER=`dirname ${FRAMEWORK_DESTINATION}` | |
mkdir -p ${DESTINATION_FOLDER} | |
cp -Rv ${FRAMEWORK_SOURCE} ${FRAMEWORK_DESTINATION} | |
CODE_SIGN_IDENTITY_FOR_ITEMS="${EXPANDED_CODE_SIGN_IDENTITY_NAME}" | |
if [ "${CODE_SIGN_IDENTITY_FOR_ITEMS}" = "" ] ; then | |
CODE_SIGN_IDENTITY_FOR_ITEMS="${CODE_SIGN_IDENTITY}" | |
fi | |
BINARY_NAME=`basename ${FRAMEWORK_DESTINATION} .framework` | |
codesign --force --verbose --sign "${CODE_SIGN_IDENTITY_FOR_ITEMS}" ${FRAMEWORK_DESTINATION}/${BINARY_NAME} | |
echo " ✅ Embedded successfully" | |
else | |
echo " ❌ Non Debug build detected - do not embed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We noticed that the script doesn't work when targeting a device. What happens is that Xcode successfully installs and runs the app when doing a clean build (or can just delete the app file from the build folder). But on a consecutive build, it shows an error when trying to install the app on the phone. Looking at the details of the error, noticed that it mentions
No code signature found.
.As a temporary fix, we skip running the script when targeting anything other than a simulator but I was wondering if you ever ran into it?