📱 iOS開發 | 🔧 CI/CD | 💻 Xcode | 🐛 除錯筆記
🔴 問題描述
這兩天在跑 CI 時突然出現錯誤訊息:
Package@swift-6.0.swift:PACKAGE-TARGET:CasePathsMacros: error: Target 'CasePathsMacros' must be enabled before it can be used
🤔 嘗試過的解法
💬 Claude 的建議
首先詢問了 Claude,得到以下步驟:
- 先更新 swift-case-paths 到最新版本
- 確保使用 "Up to Next Major Version"
- 執行
File → Packages → Reset Package Caches - Clean Build Folder (Cmd + Shift + K)
- 重新 Build
結果:一看就知道沒用 😅
🤖 ChatGPT 的建議
接著試了 ChatGPT 的解法,主要是降低引用到的 package 版本。繞了一圈,還是沒用。
✅ 最終解決方案
最後還是回到 Google,找到了真正有效的解法。針對這個 macro fingerprint validation 問題,有三種解決方式:
📌 方法一:本機開發用(Terminal 指令)
defaults write com.apple.dt.Xcode IDESkipMacroFingerprintValidation -bool YES
📌 方法二:xcodebuild 參數
在執行 xcodebuild 指令時,加上 -skipMacroValidation 參數
📚 參考連結:https://vocus.cc/article/690779ebfd89780001859b14
📌 方法三:CI 正統做法 ⭐️(推薦)
步驟 1:在專案根目錄建立資料夾 ci_scripts
步驟 2:在此資料夾中建立腳本 ci_post_clone.sh,內容如下:
#!/bin/zsh
mkdir -p ~/Library/org.swift.swiftpm/security/
cp macros.json ~/Library/org.swift.swiftpm/security/
步驟 3:將本機的 ~/Library/org.swift.swiftpm/security/macros.json 檔案複製到同一個 ci_scripts 資料夾中
💡 心得結論
這次的經驗讓我學到:
- 🤖 AI 工具不是萬能,遇到系統設定問題,傳統搜尋引擎仍然很重要
- 🔍 關鍵字很重要!這次成功的關鍵字是:
"CI must be enabled before it can be used" - 📚 Google 搜尋到正確的關鍵字,往往能找到最準確的答案
- ⚙️ 系統層級的設定問題,需要針對性的解決方案
相關標籤: iOS開發 | CI/CD | Xcode | Swift Package Manager | 除錯 | Macro Validation
留言