xcode9 Framework製作自動打包指令碼自動build版本__framework

來源:互聯網
上載者:User
前言

網上關於Framework製作的教程數不勝數,這裡我只是自己製作framework的過程記錄下來,使用的是Xcode9環境。


本文

1. 首先建立一個項目,選擇Cocoa touch Framework


2. 起名字建立工程,然後將要封裝成framework的代碼拖入工程


3. 設定Build Settings

    (1). bitcode設定

        

    (2). Linking設定

        將Link With Standard Libraries關閉(用不到就關閉吧,否則也許會不相容),Mach-O Type設為Static Library,framework可以是動態庫也可以是靜態庫,設定為靜態庫可以直接在引入工程中使用要加other linker -ObjC -all_load, 對於動態庫則需要在工程中匯入Embedded Binaries否則會報Reason: image not found。

    

    動態庫的使用注意:

    


4. 合并模擬器版本和真機版本

lipo -create "${DEVICE_DIR}/${FMK_NAME}" "${SIMULATOR_DIR}/${FMK_NAME}" -output "${INSTALL_DIR}/${FMK_NAME}"

使用以上命令手工合并framework

下面我們使用指令碼自動合并framework,步驟如下:

    (1). 建立新的aggregate,隨便起名吧

    

    (2). 簡單指令碼配置


# Sets the target folders and the final framework product.# 如果工程名稱和Framework的Target名稱不一樣的話,要自訂FMKNAME# 例如: FMK_NAME = "MyFramework"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.WORK_DIR=buildDEVICE_DIR=${WORK_DIR}/${CONFIGURATION}-iphoneos/${FMK_NAME}.frameworkSIMULATOR_DIR=${WORK_DIR}/${CONFIGURATION}-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION} "Release"# Clean and Building both architectures.xcodebuild -configuration “Release" -target "${FMK_NAME}" -sdk iphoneos clean buildxcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build# Cleaning the oldest.if [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"cp -R "${SIMULATOR_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 "${WORK_DIR}"open "${INSTALL_DIR}"

(3). 帶版本控制指令碼配置

想要獲得版本資訊就要先設定info.plist檔案,在build Settings中設定,當然是在你建立的aggregate中設定

這時我們就可以通過PlistBuddy獲得plist中的值,也可以設定。

# Sets the target folders and the final framework product.# 如果工程名稱和Framework的Target名稱不一樣的話,要自訂FMKNAME# 例如: FMK_NAME = "MyFramework"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.#${SDK_NAME}#SDK_VERSION=$(echo ${SDK_NAME} | grep -o '.{3}$')#/${DYLIB_CURRENT_VERSION}#/${CURRENT_PROJECT_VERSION}#版本擷取echo "${PROJECT_DIR}/${INFOPLIST_FILE}"buildNumber=$(/usr/libexec/PlistBuddy -c "Print :CFBundleVersion" "${PROJECT_DIR}/${INFOPLIST_FILE}")buildNumber="$buildNumber"echo "buildNumber = $buildNumber"shortVersion=$(/usr/libexec/PlistBuddy -c "Print :CFBundleShortVersionString" "${PROJECT_DIR}/${INFOPLIST_FILE}")shortVersion="$shortVersion"echo "shortVersion = $shortVersion"#自增build版本buildVersion=$(echo ${buildNumber} | grep -o -E '\d{1,3}$')buildVersion=$(($buildVersion + 1))buildVersion=".$buildVersion"echo "buildVersion = $buildVersion"#設定build版本newBuildNumber="$shortVersion$buildVersion"echo "newBuildNumber = $newBuildNumber"/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newBuildNumber" "${PROJECT_DIR}/${INFOPLIST_FILE}"INSTALL_DIR=${SRCROOT}/Products/${buildNumber}/${FMK_NAME}.framework# Working dir will be deleted after the framework creation.WORK_DIR=buildDEVICE_DIR=${WORK_DIR}/Release-iphoneos/${FMK_NAME}.frameworkSIMULATOR_DIR=${WORK_DIR}/Release-iphonesimulator/${FMK_NAME}.framework# -configuration ${CONFIGURATION} "Release"# Clean and Building both architectures.xcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphoneos clean buildxcodebuild -configuration "Release" -target "${FMK_NAME}" -sdk iphonesimulator clean build# Cleaning the oldest.if [ -d "${INSTALL_DIR}" ]thenrm -rf "${INSTALL_DIR}"fimkdir -p "${INSTALL_DIR}"cp -R "${DEVICE_DIR}/" "${INSTALL_DIR}/"cp -R "${SIMULATOR_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 "${WORK_DIR}"rm -rf "${INSTALL_DIR}/_CodeSignature"rm -rf "${INSTALL_DIR}/Info.plist"open "${INSTALL_DIR}"

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.