制作Framework并支持Bitcode

Framework -> demo <- 下载

  1. 新建一个项目用于测试 Framework(FrameworkDemo)

  2. 在该项目里面创建 Framework(HelloFramework)


    制作Framework并支持Bitcode_第1张图片
    创建Framework
  • Mach-O Type 将 Dynimic Library 修改为 Static Library


    制作Framework并支持Bitcode_第2张图片
    修改 Mach-O Type
  • 将需要公开的 .h 文件拖放到 Public 目录下


    制作Framework并支持Bitcode_第3张图片
    公开 .h 文件
  • 如果需要支持 Bitcode,需要在 Build Settings -> Deployment 中打开 DEPLOYMENT_POSTPROCESSING = YES,
    设置 STRIP_STYLE 为 Debugging Symbols,
    Build Settings -> Compiler Flags添加 -fembed-bitcode 参数。


    制作Framework并支持Bitcode_第4张图片
    支持 Bitcode,Deployment

    制作Framework并支持Bitcode_第5张图片
    支持 Bitcode,Compiler Flags
  1. 创建 bundle,放置资源文件(xib 文件,图片)
  • 新建一个空文件(HelloFramework)
  • 把需要用的图片放进 HelloFramework 文件里面
  • 编译 framework


    制作Framework并支持Bitcode_第6张图片
  • 在 finder 里,会找到一个 xxx.nib 文件,copy 出来放到 HelloFramework 文件夹里(如果 xib 文件有改动,就需要重新编译和替换)


    制作Framework并支持Bitcode_第7张图片
  • 然后更改文件名后缀为 .bundle


    制作Framework并支持Bitcode_第8张图片
    更改后缀为 .bundle
  1. Framework 导出
    手动导出Framework
  • 在 Target 为 HelloFramework 下,选择模拟器和 Generic iOS Device 各自 Build 一次
  • 在工程目录 Products 下→右击 HelloFramework→Show in Finder,会看到有两个文件夹,一个是真机包,一个是模拟器包。然后终端通过 lipo 命令将两个 Framework 文件合成
    //合并 Framework 文件命令(注意空格)
lipo -create Debug-iphoneos/xxFramework Debug-iphonesimulator/xxFramework -output xx/xxFramework

lipo -create Release-iphoneos/xxFramework Release-iphonesimulator/xxFramework -output xx/xxFramework

//查看 Framework 的类型

lipo –info xxFramework
i386 armv7 x86_64 arm64 
  • 替换 Framework
    shell脚本自动导出 Framework(该脚本在 Xcode 10 上存在问题)
  • 新建一个 Aggregate,并添加脚本


    制作Framework并支持Bitcode_第9张图片
    1

    制作Framework并支持Bitcode_第10张图片
    2

    制作Framework并支持Bitcode_第11张图片
    3
  • 把下面的脚本复制到 Run Script 里面
# Sets the target folders and the final framework product.
# 如果工程名称和 Framework 的 Target 名称不一样的话,要自定义 FMKNAME
FMK_NAME="HelloFramework"
#FMK_NAME=${PROJECT_NAME}

# 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}"
  • 选中我们刚才创建的 Aggregate 这个 target,然后 Build,就可以坐等结果了。


    制作Framework并支持Bitcode_第12张图片
    4

你可能感兴趣的:(制作Framework并支持Bitcode)