-
-
Save adamzarn/6bb89d91ed4b8c3d3fb25363c221441f to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# Usage: | |
# 1. Copy the script into a text editor and save it with no extension | |
# 2. Make it executable like so: chmod +x path/to/script | |
# 3. Run it from the Terminal in one of two ways: | |
# * path/to/script ipa_path="path/to/ipa" archive_path="path/to/xcarchive" | |
# * path/to/script ipa_path="path/to/ipa" toolchain_path="path/to/toolchain" | |
for ARGUMENT in "$@" | |
do | |
KEY=$(echo $ARGUMENT | cut -f1 -d=) | |
VALUE=$(echo $ARGUMENT | cut -f2 -d=) | |
case "$KEY" in | |
ipa_path) ipaPath=${VALUE} ;; # Format: "Path/to/app.ipa" | |
archive_path) archivePath=${VALUE} ;; # Format: "Path/to/app.xcarchive" | |
toolchain_path) toolchainPath=${VALUE} ;; # Format: "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.0/iphoneos" | |
*) | |
esac | |
done | |
# Derived Variables | |
ipaDirectory=$(dirname "$ipaPath") | |
ipaName=$(basename "$ipaPath") | |
zipName=${ipaName/.ipa/.zip} | |
appName=${ipaName/.ipa/} | |
zipSuffix=-unzipped | |
unzippedDirectoryName=${appName}${zipSuffix} | |
newIpaSuffix=-with-swift-support | |
newIpaName=${appName}${newIpaSuffix} | |
swiftSupportPath=SwiftSupport/iphoneos | |
ipaSwiftSupportDirectory=${ipaDirectory}/${unzippedDirectoryName}/${swiftSupportPath} | |
# Changes the .ipa file extension to .zip and unzips it | |
function unzipIPA { | |
mv "${ipaDirectory}/${ipaName}" "${ipaDirectory}/${zipName}" | |
unzip "${ipaDirectory}/${zipName}" -d "${ipaDirectory}/${unzippedDirectoryName}" | |
} | |
# Copies the SwiftSupport folder from the .xcarchive into the .ipa | |
function copySwiftSupportFromArchiveIntoIPA { | |
mkdir -p "$ipaSwiftSupportDirectory" | |
cd "${archivePath}/${swiftSupportPath}" | |
for file in *.dylib; do | |
cp "$file" "$ipaSwiftSupportDirectory" | |
done | |
} | |
# Creates the SwiftSupport folder from the Xcode toolchain and copies it into the .ipa | |
function copySwiftSupportFromToolchainIntoIPA { | |
mkdir -p "$ipaSwiftSupportDirectory" | |
cd "${ipaDirectory}/${unzippedDirectoryName}/Payload/${appName}.app/Frameworks" | |
for file in *.dylib; do | |
cp "${toolchainPath}/${file}" "$ipaSwiftSupportDirectory" | |
done | |
} | |
# Adds the SwiftSupport folder from one of two sources depending on the presence of an .xcarchive | |
function addSwiftSupportFolder { | |
if [ -z "$archivePath" ] | |
then | |
copySwiftSupportFromToolchainIntoIPA | |
else | |
copySwiftSupportFromArchiveIntoIPA | |
fi | |
} | |
# Zips the new folder back up and changes the extension to .ipa | |
function createAppStoreIPA { | |
cd "${ipaDirectory}/${unzippedDirectoryName}" | |
zip -r "${ipaDirectory}/${newIpaName}.zip" ./* | |
mv "${ipaDirectory}/${newIpaName}.zip" "${ipaDirectory}/${newIpaName}.ipa" | |
} | |
# Renames original .ipa and deletes the unzipped folder | |
function cleanUp { | |
mv "${ipaDirectory}/${zipName}" "${ipaDirectory}/${ipaName}" | |
rm -r "${ipaDirectory}/${unzippedDirectoryName}" | |
} | |
# Execute Steps | |
unzipIPA | |
addSwiftSupportFolder | |
createAppStoreIPA | |
cleanUp |
@adamzarn Thanks for posting this.
Does the script assume that the app uses Swift so the libraries will be present under Frameworks in the ipa?
I'm pretty sure my app doesn't use Swift but I'm still getting Invalid Swift Support error. It doesn't make any difference if I have "Always Embed Swift binaries" in the build settings set to Yes or No. If I just add an empty folder I get the 90424 SwiftSupport folder is empty error. This is with XCode 12.4
+1
In my case the error was nothing to do with Swift and was because I was trying to include dynamically linked openssl libraries in my app. Whilst this is fine for running an app in the simulator or on a development device, the Apple Store won't accept random libraries in the Frameworks folder and sends this unhelpful message.
The solution was to link the libraries statically. https://forum.qt.io/post/647893
The script mentioned above does not add all the *.dylib files to swiftsupport directory. Instead use https://github.com/NityaSantosh26/add-swift-support/blob/main/swift-support
@adamzarn Thanks for posting this.
Does the script assume that the app uses Swift so the libraries will be present under Frameworks in the ipa?
I'm pretty sure my app doesn't use Swift but I'm still getting Invalid Swift Support error. It doesn't make any difference if I have "Always Embed Swift binaries" in the build settings set to Yes or No. If I just add an empty folder I get the 90424 SwiftSupport folder is empty error. This is with XCode 12.4