Skip to content

Instantly share code, notes, and snippets.

@phatblat
Created May 11, 2015 16:53
Show Gist options
  • Save phatblat/6eb8895e2202f796960e to your computer and use it in GitHub Desktop.
Save phatblat/6eb8895e2202f796960e to your computer and use it in GitHub Desktop.
A quick script to package up an .ipa correctly since `xcodebuild -exportArchive` misses the required SwiftSupport and WatchKitSupport folders
#!/bin/bash -e
#
# package-ipa.sh
#
# Bundles an iOS app correctly, using the same directory structure that Xcode does when using the export functionality.
#
xcarchive="$1"
output_ipa="$2"
build_dir=$(mktemp -d '/tmp/package-ipa.XXXXXX')
echo "build_dir: $build_dir"
if [ ! -d "${xcarchive}" ]; then
echo "Usage: package-ipa.sh /path/to/app.xcarchive /path/to/ouput.ipa"
exit 1
fi
echo "Packaging ${xcarchive} into ${output_ipa}"
if [ -f "${output_ipa}" ]; then
rm "${output_ipa}"
fi
# if [ -d "${build_dir}" ]; then
# rm -rf "${build_dir}"
# fi
echo "Preparing folder tree for IPA"
mkdir -p "${build_dir}/Payload"
# Copy .app into Payload dir
pushd "${xcarchive}/Products/Applications" > /dev/null
ls -l
cp -Rp ./*.app "${build_dir}/Payload"
popd > /dev/null
# Check for and copy swift libraries
if [ -d "${xcarchive}/SwiftSupport" ]; then
echo "Adding Swift support dylibs"
cp -Rp "${xcarchive}/SwiftSupport" "${build_dir}/"
fi
# Check for and copy WatchKit file
if [ -d "${xcarchive}/WatchKitSupport" ]; then
echo "Adding WatchKit support file"
cp -Rp "${xcarchive}/WatchKitSupport" "${build_dir}/"
fi
echo "Zipping"
pushd "${build_dir}" > /dev/null
zip --symlinks --verbose --recurse-paths "${output_ipa}" .
popd > /dev/null
rm -rf "${build_dir}"
echo "Created ${output_ipa}"
@fvvliet
Copy link

fvvliet commented Sep 16, 2015

Nice script, works great !!
It doesn't include the Symbols folder, is this folder required ?

thanks
Frank

@dlprows
Copy link

dlprows commented Oct 8, 2015

There's actually a new flag to use when you're creating your IPA from an XCArchive. That way you won't have to have a custom script.
http://encyclopediaofdaniel.com/blog/xcarchive-to-ipa/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment