一、老項目的描述:
首先來描述一下我所謂的老項目,項目創(chuàng)建于12年,至今的五年時間中未重構過,目前項目的內(nèi)存管理機制是使用的MRC ┭┮﹏┭┮,對于第三方依賴庫是純手工管理 ~ o(>_<)o ~。
二、所填坑的解決辦法:.
Cocoapods 的安裝和使用我就不多說了,網(wǎng)上一抓一大把。
在多次填坑之后我終于將 Cocoapods 成功的添加到項目中,下面說說我填過的這些坑們:
- 第一枚坑:在添加或者更新 Cocoapods 時,終端打印如下錯誤
[!] The `MaiChang [Debug]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-MaiChang/Pods-MaiChang.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
[!] The `MaiChang [Release]` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `Pods/Target Support Files/Pods-MaiChang/Pods-MaiChang.release.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.
產(chǎn)生此警告的原因是項目 Target 中的一些設置,CocoaPods 也做了默認的設置,如果兩個設置結果不一致,就會造成問題。解決辦法:把項目中的對應設置用 $(inherited) 替換掉??蓞⒖枷聢D

設置OTHER_LDFLAGS.png

設置ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES.png
- 第二枚坑:在填完第一個坑之后,發(fā)現(xiàn)通過 Cocoapods 導入的依賴庫, Xcode 在編譯時報錯提示找不到
ld: library not found for -lSDAutoLayout
原因我忘記了(╯﹏╰)。解決辦法可見下圖:

Edit Scheme.png
- 第三枚坑:項目手動引用了 swift 的依賴庫,項目在運行成功掛掉,控制臺打印如下錯誤
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /private/var/containers/Bundle/Application/B221905D-47DC-4760-B3FE-81452B9111EB/MaiChang.app/Frameworks/SocketIO.framework/SocketIO
Reason: image not found
Message from debugger: Terminated due to signal 6
產(chǎn)生此警告的原因是因為,項目沒有正確的嵌入 swift 標準庫。其實根本上因為對 ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES 的設置有誤引起的問題。解決辦法:檢查 Target 中該選項的值是否為Yes。(/(ㄒoㄒ)/~~這樣就造成更新 Cocoapods 時出現(xiàn)警告,具體見第一枚坑。所以在使用 Cocoapods 管理依賴庫的時候,不建議手動導入依賴庫)
- 第四枚坑:原來手動添加的庫修改為 Cocoapods 管理,運行報錯
Apple Mach-O Linker (ld) Error Group
error: Invalid bitcode signature
clang: error: linker command failed with exit code 1 (use -v to see invocation)
原因不知道。解決辦法見下圖:

設置 Build Active Architecture Only.png
- 第五枚坑:使用 @import XXX; 導入模塊時報錯
Use of '@import' when modules are disabled
Apple 在 LLVM5.0 引入了一個新的編譯符號 @import 。較老的代碼,需要在Build Settings中將Enable Modules(C and Objective-C)打開。如下圖:

設置 Enable Modules.png
期待你的評論建議O(∩_∩)O~