OC

Framework Archive

Posted on 2022-07-20,3 min read

记录下Run Script:合并真机armv7 arm64 模拟器i386 x86_64 为新的framework;同时创建xcframework


# 编译产物
# ~Library/Developer/Xcode/DerivedData/LinkPlayLogRecordDemo-cnaglpbkttarzjgcbeksqtomgylq/Build/Products/Debug-universal
UNIVERSAL_OUTPUTFOLDER=${BUILD_DIR}/${CONFIGURATION}-universal
# Products 路径
INSTALL_DIR=${SRCROOT}/Products
# framework 名字
PROJECT_IOT="LinkPlayLogRecord"
# 创建 Debug-universal
mkdir -p "${UNIVERSAL_OUTPUTFOLDER}"
# 如果有 Products 文件夹,则删除重建
if [ -d "${INSTALL_DIR}" ]; then
rm -rf "${INSTALL_DIR}"
fi
mkdir -p "${INSTALL_DIR}"

echo "[FW Script] ---------------- start -----------------"
echo "[FW Script] TARGET_BUILD_DIR: ${TARGET_BUILD_DIR}"
echo "[FW Script] CONFIGURATION: ${CONFIGURATION}"
echo "[FW Script] ACTION: ${ACTION}"
# 防止递归
if [ "false" == ${ALREADYINVOKED:-false} ]; then
    # action 为 install, 并且 TARGET_BUILD_DIR 中包含 LinkPlayLogRecordDemo
    IPHONEOS_FRAMEWORK_DIR="${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_IOT}.framework"
    IPHONESIMULATOR_FRAMEWORK_DIR="${BUILD_DIR}/${CONFIGURATION}-iphonesimulator/${PROJECT_IOT}.framework"
    if [ "${ACTION}" = "install" ] && [[ "${TARGET_BUILD_DIR}" == *"LinkPlayLogRecordDemo"* ]]; then
        export ALREADYINVOKED="true"
        # 编译模拟器 i386 x86_64 架构的 framework 包
        echo "[FW Script] xcodebuild: i386 x86_64"
        xcodebuild -target "${PROJECT_IOT}" -configuration ${CONFIGURATION} -sdk iphonesimulator -arch i386 -arch x86_64 ONLY_ACTIVE_ARCH=NO BUILD_DIR="${BUILD_DIR}" BUILD_ROOT="${BUILD_ROOT}" clean build
        # copy BUILD_DIR 下 真机包到 universal 文件夹下
        echo "[FW Script] copy iphoneos to universal"
        cp -R "${IPHONEOS_FRAMEWORK_DIR}/" "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_IOT}.framework"

        # 合并 模拟器 和  真机 framework,并输出到 universal 文件夹下
        IPHONEOS_FILE_DIR="${IPHONEOS_FRAMEWORK_DIR}/${PROJECT_IOT}"
        IPHONESIMULATOR_FLIE_DIR="${IPHONESIMULATOR_FRAMEWORK_DIR}/${PROJECT_IOT}"
        echo "[FW Script] 合并framework"
        lipo -create -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_IOT}.framework/${PROJECT_IOT}" ${IPHONESIMULATOR_FLIE_DIR} ${IPHONEOS_FILE_DIR}
        
        # 净化代码用的,本地没安装过,暂时注释了
        # coan spin "${BUILD_DIR}/${CONFIGURATION}-iphoneos/${PROJECT_IOT}.framework/Headers" --recurse --discard drop --keepgoing --implicit --gag error --define LINKPLAY_PUBLIC_HEADER=1 --define LINKPLAY_CAR_PUBLIC_HEADER=1

        # 顺便生成下 xcframework
        echo "[FW Script] 创建xcframework"
        xcodebuild -create-xcframework -framework ${IPHONEOS_FRAMEWORK_DIR} -framework ${IPHONESIMULATOR_FRAMEWORK_DIR} -output "${UNIVERSAL_OUTPUTFOLDER}/${PROJECT_IOT}.xcframework"

        # 打开 Products 文件夹
        open "${UNIVERSAL_OUTPUTFOLDER}"
        # 将其 真机framework copy 到 Products 文件夹下面
        cp -R "${IPHONEOS_FRAMEWORK_DIR}/" "${INSTALL_DIR}/${PROJECT_IOT}.framework"
    else
        echo "[FW Script] PLATFORM_NAME: ${PLATFORM_NAME}"
        # 根据 platform 是iphoneos 还是 iphonesimulator 找到对应的 framework 文件
        SOURCE_DIR=${IPHONEOS_FRAMEWORK_DIR}
        if [ ${PLATFORM_NAME} = "iphonesimulator" ]; then
            SOURCE_DIR=${IPHONESIMULATOR_FRAMEWORK_DIR}
        fi
        # 将其 copy 到 Products 文件夹下面
        cp -R ${SOURCE_DIR} "${INSTALL_DIR}/${PROJECT_IOT}.framework"
    fi
else
    echo "[FW Script] 递归 - 跳过"
fi
echo "[FW Script] ---------------- end -----------------"

下一篇: 将OC转为 C/C++→

loading...