制作Framework并支持Bitcode

Framework -> demo <- 下载

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

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


    创建Framework
  • Mach-O Type 将 Dynimic Library 修改为 Static Library


    修改 Mach-O Type
  • 将需要公开的 .h 文件拖放到 Public 目录下


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


    支持 Bitcode,Deployment

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


  • 在 finder 里,会找到一个 xxx.nib 文件,copy 出来放到 HelloFramework 文件夹里(如果 xib 文件有改动,就需要重新编译和替换)


  • 然后更改文件名后缀为 .bundle


    更改后缀为 .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,并添加脚本


    1

    2

    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,就可以坐等结果了。


    4
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容