Fri, May 29, 2020 3:43 PM
Xcode
Framework
約莫一年前因為公司的需求,製作過 oc
的 framework;但是沒有做過 Swift
的 framework,就讓我捲起袖子用力的把坑給踏平吧!
Xcode 版本 11.5 (11E608c)
Learn More →
建立好專案後先做點基本設定。
Valid Architectures
要增加 i386
、x86_64
,否則無法在模擬器上執行。當設為 NO 時,會編譯所有版本。
一般 Debug 模式可以選擇設為 YES,Release 的时候為 NO,以適用不同裝置。
dead
、unreachable
程式碼進行過濾。在這之前請先嘗試 command(⌘) + B
確認是否順利執行。
寫完程式碼後 command(⌘) + B
發現噴錯了?
Ld /Users/CK/Library/Developer/Xcode/DerivedData/MHLogKit-dapqqhqbxveeudcnjhhnvrahekvo/Build/Products/Debug-iphonesimulator/MHLogKit.framework/MHLogKit normal x86_64 (in target 'MHLogKit' from project 'MHLogKit')
cd /Users/CK/Documents/Personal/iOS/Swift/Framwork/MHLogKit
解決方式,來到 Xcode:
TARGETS
-> Build Phases
-> Link Binary With Libraries
-> +
-> libSystem.tbd
Learn More →
再次 command(⌘) + B
,完成。
因為指令集的關係 實幾
與 模擬器
是不相同的,但打包使用必須使用終端機;科技始終來自人性的慵懶!為了方便日後使用這邊提供一個 shell script
讓你在編譯後就完成打包的工作。
來到 Xcode:
Learn More →
Learn More →
Learn More →
選擇 New Run Script Phase
將語法貼上,如圖所示:
Learn More →
# Merge Script
# 1
# Set bash script to exit immediately if any commands fail.
set -e
# 2
# Setup some constants for use later on.
FRAMEWORK_NAME="Your framework name"
# 3
# If remnants from a previous build exist, delete them.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi
# 4
# Build the framework for device and for simulator (using
# all needed architectures).
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch arm64 -arch armv7 -arch armv7s only_active_arch=no defines_module=yes -sdk "iphoneos"
xcodebuild -target "${FRAMEWORK_NAME}" -configuration Release -arch x86_64 -arch i386 only_active_arch=no defines_module=yes -sdk "iphonesimulator"
# 5
# Remove .framework file if exists on Desktop from previous run.
if [ -d "${HOME}/Desktop/${FRAMEWORK_NAME}.framework" ]; then
rm -rf "${HOME}/Desktop/${FRAMEWORK_NAME}.framework"
fi
# 6
# Copy the device version of framework to Desktop.
cp -r "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework" "${HOME}/Desktop/${FRAMEWORK_NAME}.framework"
# 7
# Replace the framework executable within the framework with
# a new version created by merging the device and simulator
# frameworks' executables with lipo.
lipo -create -output "${HOME}/Desktop/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphoneos/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}" "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/${FRAMEWORK_NAME}"
# 8
# Copy the Swift module mappings for the simulator into the
# framework. The device mappings already exist from step 6.
cp -r "${SRCROOT}/build/Release-iphonesimulator/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule/" "${HOME}/Desktop/${FRAMEWORK_NAME}.framework/Modules/${FRAMEWORK_NAME}.swiftmodule"
# 9
# Delete the most recent build.
if [ -d "${SRCROOT}/build" ]; then
rm -rf "${SRCROOT}/build"
fi
若編譯成功,打包好的 framework 會出現在 桌面
,這時候就能將其拉進其他專案內使用了。
[time=Mon, Mar 12, 2018 12:22 PM]
Aug 14, 2024[time=Mon, Apr 10, 2023 1:21 PM] 最近因為工作上需要將 Excel 檔案轉成 iOS、Android 專案可用的語言包,由於以前有其他同事分享的 php 程式碼又加上最近有接觸一點 Python,剛好藉此機會寫寫 Python 的腳本。 至於為什麼會需要打包成 Packge?主因是維護方便,原先預計這個腳本就單純 iOS 專案自己使用,但因為需求兩邊平台一致變成也要同時支援 Android;加上我不想同時維護兩邊的專案,綜述以上種種就來打包成 Packge 吧。 讓我們開始吧 Pythone 版本因應你的程式碼,這裡沒有特別限制 1. 能跑的 code
Apr 10, 2023[time=Mon, Apr 25, 2022 9:30 AM] 假設現在有一簡單註冊需求: 帳號輸入框;帳號最少 6 個字。 密碼輸入框;密碼最少 8 個字。 驗證密碼輸入框;驗證密碼需與密碼完全相同。 註冊送出按鈕;按下送出後檢查上述條件。 註冊成功;彈出提示 註冊成功,反之註冊失敗。
Apr 27, 2022[time=Fri, Oct 29, 2021 5:03 PM] fastlane 是為了爭取工程師更多摸魚時間的最大利器,不再需要各種確認後才開始打包流程;現在,就讓我們手把手來安裝這解放自由的好物吧。 fastlane 可以用在 iOS 與 Android,因本人為 iOS 工作者,此次就以 iOS 專案為示範輸出 ad-Hoc ipa。 一、安裝 因 fastlane 需要使用 Xcode 指令工具。
Nov 1, 2021or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up