制作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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容