Before Xcode was going to build modules, so let’s not say so
Post the shell script to be added, convenient and practical.
# Sets the target folders and the final framework product.
If the project name is not the same as the Framework Target name, use a custom FMKNAME
# example: FMK_NAME = "MyFramework"
FMK_NAME="SLFMWK"
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_DIR=${SRCROOT}/Products/${FMK_NAME}.framework
# Working dir will be deleted after the framework creation.
WRK_DIR=build
DEVICE_DIR=${WRK_DIR}/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WRK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework
# -configuration ${CONFIGURATION}
# Clean and Building both architectures.
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean build
xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build
# Cleaning the oldest.
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"
rm -r "${WRK_DIR}"
open "${INSTALL_DIR}"
Copy the code
Package the merged static library of.a
if [ "${ACTION}" = "build" ]
then
The target name to build
target_Name=${PROJECT_NAME}
echo "target_Name=${target_Name}"
The folder path after build
build_DIR=${SRCROOT}/build
echo "build_DIR=${build_DIR}"
The path to the header files generated by build
DEVICE_DIR_INCLUDE=${build_DIR}/Release-iphoneos/include/${PROJECT_NAME}
echo "DEVICE_DIR_INCLUDE=${DEVICE_DIR_INCLUDE}"
The path to the.a file generated by build
DEVICE_DIR_A=${build_DIR}/Release-iphoneos/lib${PROJECT_NAME}.a
echo "DEVICE_DIR_A=${DEVICE_DIR_A}"
The path to the.a file generated by simulator build
SIMULATOR_DIR_A=${build_DIR}/Release-iphonesimulator/lib${PROJECT_NAME}.a
echo "SIMULATOR_DIR_A=${SIMULATOR_DIR_A}"
# Destination folder path
INSTALL_DIR=${SRCROOT}/Products/${PROJECT_NAME}
echo "INSTALL_DIR=${INSTALL_DIR}"
The destination header folder path
INSTALL_DIR_Headers=${SRCROOT}/Products/${PROJECT_NAME}/Headers
echo "INSTALL_DIR_Headers=${INSTALL_DIR_Headers}"
# target.a path
INSTALL_DIR_A=${SRCROOT}/Products/${PROJECT_NAME}/lib${PROJECT_NAME}.a
echo "INSTALL_DIR_A=${INSTALL_DIR_A}"
If the build folder exists, delete it
if [ -d "${build_DIR}" ]
then
rm -rf "${build_DIR}"
fi
# Check whether the target folder exists, delete the folder if it does
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
Create a target folder
mkdir -p "${INSTALL_DIR}"
Clean up before build
xcodebuild -target ${target_Name} clean
# emulator build
xcodebuild -target ${target_Name} -configuration Release -sdk iphonesimulator
# machine build
xcodebuild -target ${target_Name} -configuration Release -sdk iphoneos
Copy the header file to the target folder
cp -R "${DEVICE_DIR_INCLUDE}" "${INSTALL_DIR_Headers}"
# Compositing simulator and real machine. A package
lipo -create "${DEVICE_DIR_A}" "${SIMULATOR_DIR_A}" -output "${INSTALL_DIR_A}"
Open the target folder
open "${INSTALL_DIR}"
fi
Copy the code
-objc Flags should be added to Other Linker Flags in Xcode’s Build Settings if there are categories in the framework. An important feature of Objective-C is the category. As explained here, there is some conflict between the standard static library implementation of Unix and the dynamic nature of Objective-C: Objective-C does not define link symbols for every function (or method), it only creates link symbols for each class. So when you’re using categories in a static library to extend an existing class, the linker doesn’t know how to integrate the methods in the class with the methods in the category, and you’re going to get “selector not recognized” when you call the methods in the category. To solve this problem, the -objc flag was introduced, which loads all the object related files in the static library. This should have fixed the problem, but on 64-bit Macs or iOS, there is a bug in the linker that prevents static libraries containing only classes from loading files using the -objc flag. The workaround is to use either the -all_load or -force_load flag, both of which load all files in the static library, but all_load applies to all libraries, and -force_load must be followed by a specific file. (If there is still a problem, the third-party library path may be added)
Making the address
The end of the