Xcode 7 製作 framework
建立工程
新增原始碼
-
新增OC原始檔
在 swift 製作 framework 新增 OC檔案時,不能設定橋接檔案,而是將 OC標頭檔案放到框架的標頭檔案中,如下圖:同時將該OC標頭檔案設定為 public(預設新增到Private,可拖動到Public):
-
新增框架原始碼
新增指令碼
新增生成模擬器與真機都可使用的 framework 的執行指令碼。
- 給框架工程新增Target:File/New/Target
指令碼內容如下(指令碼內容是從網上搜尋到的,但在工程中一直出現問題,無法用於模擬器,後來發現是缺少了cp -R "${SIMULATOR_DIR}/" "${INSTALL_DIR}/"
):
# 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.
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}/"
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 "${WRK_DIR}"
open "${INSTALL_DIR}"
-
編譯指令碼:Product/Build For/Profiling
編譯完指令碼會自動彈出生成的framework的資料夾。
新增framework到工程
-
將目標 framework 和其所用到的資原始檔拖到目標工程中
-
新增目標框架到複製檔案中去
�打包提交到 App Store
在使用自制的 Framework 的應用程式打包提交到 App Store 的時候,可能會遇到以下問題“Unsupported architectures. Your executable contains unsupported architectures '[x86_64, i386]'”
,此時在你要打包提交的目標程式的Build Phases
下新增Run Script
,並將以下內容複製進去:
APP_PATH="${TARGET_BUILD_DIR}/${WRAPPER_NAME}"
# This script loops through the frameworks embedded in the application and
# removes unused architectures.
find "$APP_PATH" -name '*.framework' -type d | while read -r FRAMEWORK
do
FRAMEWORK_EXECUTABLE_NAME=$(defaults read "$FRAMEWORK/Info.plist" CFBundleExecutable)
FRAMEWORK_EXECUTABLE_PATH="$FRAMEWORK/$FRAMEWORK_EXECUTABLE_NAME"
echo "Executable is $FRAMEWORK_EXECUTABLE_PATH"
EXTRACTED_ARCHS=()
for ARCH in $ARCHS
do
echo "Extracting $ARCH from $FRAMEWORK_EXECUTABLE_NAME"
lipo -extract "$ARCH" "$FRAMEWORK_EXECUTABLE_PATH" -o "$FRAMEWORK_EXECUTABLE_PATH-$ARCH"
EXTRACTED_ARCHS+=("$FRAMEWORK_EXECUTABLE_PATH-$ARCH")
done
echo "Merging extracted architectures: ${ARCHS}"
lipo -o "$FRAMEWORK_EXECUTABLE_PATH-merged" -create "${EXTRACTED_ARCHS[@]}"
rm "${EXTRACTED_ARCHS[@]}"
echo "Replacing original executable with thinned version"
rm "$FRAMEWORK_EXECUTABLE_PATH"
mv "$FRAMEWORK_EXECUTABLE_PATH-merged" "$FRAMEWORK_EXECUTABLE_PATH"
done
到此就結束了
參考
相關文章
- Xcode 6製作動態及靜態FrameworkXCodeFramework
- 簡單的製作frameworkFramework
- iOS Xcode打包frameworkiOSXCodeFramework
- 簡述iOS開發framework製作與使用iOSFramework
- iOS,製作屬於自己cocoapods,(framework,bundle)iOSFramework
- iOS 製作靜態庫(.a檔案)(Xcode9)iOSXCode
- framework7Framework
- 《最終幻想7:重製版》遊戲音訊製作分享遊戲音訊
- 7z製作自解壓安裝包
- cnetos7 ISO 映象自定義製作
- Xcode如何找到FrameWork對應的原始碼的XCodeFramework原始碼
- [Fireworks+Dreamweaver製作網站]第7課上網站
- xcode7 獲取 LaunchImageXCode
- Xcode7安裝AlcatrazXCode
- 實戰!教你如何使用KVM製作centos7映象!CentOS
- 給遊戲開發者們的 7 個製作建議遊戲開發
- Xcode 7 中的 UI 測試XCodeUI
- Django REST framework API 指南(7):解析DjangoRESTFrameworkAPI
- Entity Framework Tutorial Basics(7):DBContextFrameworkContext
- Framework7 無限滾動Framework
- Html 製作HTML
- Kris Graft:分享製作道德遊戲的7條實用建議Raft遊戲
- framework7-vue ^2.x pushStateFrameworkVue
- Entity Framework Code-First(7):Inheritance StrategyFramework
- Xcode7 真機測試設定XCode
- 價目表製作報價單製作軟體
- 7天銷量破百萬,《破曉傳說》製作團隊專訪
- 製作原生APPAPP
- 地圖製作地圖
- 如何製作DVDrip?
- excel製作表格時 怎麼製作Excel斜表頭Excel
- xcode7免證書真機除錯XCode除錯
- Xcode7 真機除錯步驟分享XCode除錯
- 在Xcode 7上直接使用Address SanitizerXCode
- Windows7系統自帶DVD 輕鬆製作照片影片的方法Windows
- EDM郵件製作
- Dockerfile映象的製作Docker
- 製作 Cocoapods 庫