Skip to content

Instantly share code, notes, and snippets.

@brennanMKE
Last active July 18, 2023 17:53
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save brennanMKE/a850b9ce7579e177fe4f78e267550cb2 to your computer and use it in GitHub Desktop.
Save brennanMKE/a850b9ce7579e177fe4f78e267550cb2 to your computer and use it in GitHub Desktop.
Check Bitcode support with Static Libraries

Check Bitcode

It is important to enable Bitcode in all libraries if the app is going to enable Bitcode. These scripts check each static library for Bitcode and echo a string which shows up as a warning in the build log. It is an easy way to always check that the dependencies have what is needed.

Usage

Place check_bitcode.sh in your project directory. Then add a Run Script in Build Phasese with the script named RunScript.sh. Name that new section as Check Bitcode and run the build. It may be necessary to make the shell script executble using chmod u+x check_bitcode.sh on the command-line.

Frameworks vs Static Libraries

It is preferable to use frameworks over static libraries. Since Xcode 8 and Swift was released use of frameworks have been encouraged by Apple. Frameworks support a lot of the new functionality supported by Xcode and iOS.

#!/bin/sh
set -e
check_bitcode() {
FILE="$1"
if [ -f $FILE ]; then
COUNT=`otool -l $FILE | grep bitcode | wc -l`
ARCH=`lipo -info $FILE | rev | cut -d ':' -f1 | rev`
if [ "$COUNT" -eq "0" ]; then
echo "warning: Missing Bitcode: ${FILE}:${ARCH}"
fi
fi
}
FILES=`find ${TARGET_BUILD_DIR} -name \*.a`
for STATIC_LIBRARY in $FILES; do
check_bitcode $STATIC_LIBRARY
done
echo "Checking Static Libraries for BitCode"
SCRIPT=${PROJECT_DIR}/check_bitcode.sh
if [ -f "${SCRIPT}" ]; then
sh ${SCRIPT}
else
echo "error: Script Not Found: ${SCRIPT}"
fi
@sindhuiOS
Copy link

try to give answer to my STO question about creating framework from terminal.

https://stackoverflow.com/q/46808851/6285383

@tylermilner
Copy link

This is a neat little script. Thanks for sharing! One minor improvement that I made:

  • Add exit 1 when the script is not found in RunScript.sh. Otherwise, the script will fail, but the build will still show as having succeeded.

Final RunScript.sh looks like:

echo "Checking Static Libraries for BitCode"

SCRIPT=${PROJECT_DIR}/check_bitcode.sh

if [ -f "${SCRIPT}" ]; then
    sh ${SCRIPT}
else
    echo "error: Script Not Found: ${SCRIPT}"
    exit 1
fi

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