You can find so many blog-posts related to “how to build Universal static library iOS”, but most of them are quite weird…
Tutorial level: Medium (must be familiar with the creation of static libraries or frameworks using Xcode)
1. One target.
Those blog-posts suggest to create two targets. One for the iphoneos platform, and one for the iphonesimulator platform. But it quickly becomes a nightmare because you have to build the iphoneos one, then the iphonesimulator one, and finally the aggregation one. NIGHTMARE.
While working on an open-source Grid-View component, I found out how to build and aggregate using only 1 target.
2. One library target, two build configurations.
That’s it, we got two basis build configurations which are Debug and Release… why not changing Debug to iphonesimulator and Release to iphoneos?
For the build configuration named “iphoneos“, use iphoneos as supported platform, and armv6, armv7 for valid architectures.
For the build configuration named “iphonesimulator“, use iphonesimulator as supported platform, and i386 for valid architectures
Do not forget to configure your Copy Headers phase properly.
3. One aggregate target, One universal library.
In your newly created ‘aggregate’ target (here called NRGridView Universal), add a Run Script phase and copy/paste the script below:
LIB_NAME=${PROJECT_NAME}
BUILD_DIR=build
# Create paths
INSTALL_DIR=${BUILD_DIR}/${LIB_NAME}
DEVICE_DIR=${BUILD_DIR}/iphoneos-iphoneos
SIMULATOR_DIR=${BUILD_DIR}/iphonesimulator-iphonesimulator
# Build our project using iphoneos and iphonesimulator build configurations
xcodebuild -configuration "iphoneos" -target "${LIB_NAME}" -sdk iphoneos
xcodebuild -configuration "iphonesimulator" -target "${LIB_NAME}" -sdk iphonesimulator
# Clean the old install directory.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
# Create the install directory
mkdir -p "${INSTALL_DIR}"
# Copy the iphoneos headers into the install directory
cp -R "${DEVICE_DIR}/usr" "${INSTALL_DIR}"
# Use lipo tool to create 1 universal library
lipo -create "${DEVICE_DIR}/lib${LIB_NAME}.a" "${SIMULATOR_DIR}/lib${LIB_NAME}.a" -output "${INSTALL_DIR}/lib${LIB_NAME}.a"
# Remove useless build directories
rm -rf "${DEVICE_DIR}" "${SIMULATOR_DIR}" "${INSTALL_DIR}.build"
4. Compile.

5. Conclusion.






