Skip to content

Instantly share code, notes, and snippets.

@kierangraham
Created November 9, 2017 17:25
Show Gist options
  • Save kierangraham/81350b3add0890b61dcd75a7bb0a124e to your computer and use it in GitHub Desktop.
Save kierangraham/81350b3add0890b61dcd75a7bb0a124e to your computer and use it in GitHub Desktop.
Calculate the before and after size difference of an iOS App Store update.
#! /usr/bin/env sh
bitcode_strip="xcrun bitcode_strip"
strip="xcrun strip"
lipo="xcrun lipo"
archives=(*.xcarchive)
if [ ! ${#archives[@]} -eq 2 ] && [ ! -e "$archives[0]" ];
then
echo "There must be two Xcode archives to calculate the before and after size of the predict.io SDK."
exit -1
fi
working_dir=~/.predictio_calculate_sdk_size
rm -rf $working_dir &> /dev/null
mkdir $working_dir
for archive in "${archives[@]}"
do
cp -R "$archive" $working_dir/
done
archives=("$working_dir/*.xcarchive")
declare -a app_sizes=(0,0)
archive_index=-1
for archive in ${archives[@]}
do
((archive_index++))
archive_basename=`basename "$archive"`
echo "\033[1m===> Processing '$archive_basename'\033[0m"
frameworks=("$archive"/Products/Applications/*.app/Frameworks/*.framework)
if [ ${#frameworks[@]} -gt 0 ] && [ -e "${frameworks[0]}" ];
then
echo " ${#frameworks[*]} frameworks to strip bitcode and architectures"
echo ""
for framework in "${frameworks[@]}"
do
[ -e "$framework" ] || continue
framework_basename=`basename "$framework"`
binary=${framework_basename//.framework/}
full_size=$(du -k "$framework/$binary" | cut -f1)
echo "\033[94m\033[1m---> $framework_basename full size... $full_size KB\033[0m"
$strip -S -T -X -x "$framework/$binary" &> /dev/null
stripped_size=$(du -k "$framework/$binary" | cut -f1)
echo "\033[2m Stripping symbols... $stripped_size KB\033[0m"
$bitcode_strip -r "$framework/$binary" -o "$framework/$binary"
nobitcode_size=$(du -k "$framework/$binary" | cut -f1)
echo "\033[2m Bitcode removed... $nobitcode_size KB\033[0m"
$lipo -thin arm64 "$framework/$binary" -o "$framework/$binary"
thinned_size=$(du -k "$framework/$binary" | cut -f1)
echo "\033[2m Single architecture slice... $thinned_size KB\033[0m"
gzip -9 < "$framework/$binary" > "$framework/$binary.gz"
gzip_size=$(du -k "$framework/$binary.gz" | cut -f1)
echo " Compressed Size... $gzip_size KB"
rm -rf "$framework/$binary.gz"
done
fi
app=("$archive"/Products/Applications/*.app)
app_name=`basename "$app"`
app_binary=${app_name//.app/}
echo ""
full_size=$(du -k "$app/$app_binary" | cut -f1)
echo "\033[94m\033[1m---> App Binary full size... $full_size KB\033[0m"
$strip -S -T -X -x "$app/$app_binary" &> /dev/null
stripped_size=$(du -k "$app/$app_binary" | cut -f1)
echo "\033[2m Stripping symbols... $stripped_size KB\033[0m"
$bitcode_strip -r "$app/$app_binary" -o "$app/$app_binary"
nobitcode_size=$(du -k "$app/$app_binary" | cut -f1)
echo "\033[2m Bitcode removed... $nobitcode_size KB\033[0m"
$lipo -thin arm64 "$app/$app_binary" -o "$app/$app_binary"
thinned_size=$(du -k "$app/$app_binary" | cut -f1)
echo "\033[2m Single architecture slice... $thinned_size KB\033[0m"
env GZIP=-9 tar -zcf "${app}.gz" "$app" &> /dev/null
gzip_size=$(du -k "${app}.gz" | cut -f1)
echo "\033[1m\033[32m===> Compressed App Size... $gzip_size KB Done!\033[0m"
app_sizes[$archive_index]=$gzip_size
echo ""
# echo "===> $archive_basename Done!"
# echo ""
done
echo "\033[1m\033[32m===> App Store Download Difference"
dl_diff=$((app_sizes[0]-app_sizes[1]))
echo " ${dl_diff/#-/} KB\033[0m"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment