iOS生成Frameworks
2021-06-08 本文已影响0人
Johnny_Wu
1、可以通过在xcode的target添加Aggregate的方式
2、直接生成shell脚本的方式
用Aggregate的方式,可以使用一些全局环境变量,比如:
SRCROOT:项目的路径

BUILD_DIR:Xcode编译生成库的路径

但通过shell脚本的方式,是不能使用上面那些全局变量的。可以使用:
WORKSPACE=$(pwd)
定位到当前shell所在的目录。
因此我写了这样一个通过版本:
set -e
FMK_NAME="mytestFrame"
WORKSPACE=$(pwd)
echo "hello-->$WORKSPACE"
INSTALL_DIR=${WORKSPACE}/Products/${FMK_NAME}.framework
DEVICE_DIR=${WORKSPACE}/build/Release-iphoneos/${FMK_NAME}.framework
SIMULATOR_DIR=${WORKSPACE}/build/Release-iphonesimulator/${FMK_NAME}.framework
xcodebuild clean build
xcodebuild -target "${FMK_NAME}" -configuration Release -arch arm64 -arch armv7 only_active_arch=no defines_module=yes -sdk "iphoneos"
xcodebuild -target "${FMK_NAME}" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator"
if [ -d "${INSTALL_DIR}" ]
then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"
cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"
rm -rf "${INSTALL_DIR}/${FMK_NAME}"
lipo -create -output "${INSTALL_DIR}/${FMK_NAME}" "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}"
rm -rf "${WORKSPACE}/build"
遗留问题:
使用这个xcodebuild编译,在Aggregate方式中,有时候会默认就生成到了Xcode的build路径,而不是在当前目录下生成编译后的库。我后面调试过程中,又都在当前目录下生成编译后的库的,暂未知道原因。