Cocoapods常見問題總結(jié)及解決方法

CocoapodsSwift 的支持不是很好,每次 XcodeCocoapods 版本更新,總有一些意外發(fā)生,這里總結(jié)下這一年半以來遇到的各種錯誤及其解決辦法,省的下次遇到又要Google一遍。

安裝淘寶 Ruby源的問題 Error fetching http://ruby.taobao.org/

由于墻的原因,安裝 Cocoapods 時(shí)有可能執(zhí)行完install命令半天都沒反應(yīng),這時(shí)就需要將 Ruby 的默認(rèn)源 https://rubygems.org/ 替換成淘寶的源,但會遇到以下錯誤:

$ gem sources -a http://ruby.taobao.org/
$ Error fetching http://ruby.taobao.org/:
  bad response Not Found 404 (http://ruby.taobao.org/specs.4.8.gz)

這是因?yàn)?,淘寶把源?http 換成 https 了,而網(wǎng)上大多數(shù)教程是舊的,沒有更新,正確的是:

$ gem sources -a https://ruby.taobao.org/

Pod Error in Xcode “Id: framework not found Pods”

執(zhí)行完 pod install 后,打開 workspace 文件,編譯,遇到以下錯誤:

Id: framework not found Pods clang: error: linker command failed with exit code 1 (use -v to see invocation)

stackoverflow解決方法的:http://stackoverflow.com/questions/31139534/pod-error-in-xcode-id-framework-not-found-pods

步驟如下:

  • 打開 workspace
  • 點(diǎn)擊 Xcode 左邊的藍(lán)色項(xiàng)目圖標(biāo)
  • 在右邊選擇對應(yīng)的 Target
  • 單擊 Genral 的 tab
  • 找到 Linked Frameworks and Libraries 的分組
  • 刪除 Pods frameworks(或 刪除Embedded Binaries下的Pod.framework
  • 關(guān)閉 Xcode,運(yùn)行 pod update
  • Clean,然后重新 Run/Build

提交App到Itunes Connect時(shí)報(bào)錯 ERROR ITMS-90635

提交 App 到 ITunes Connect 審核時(shí)報(bào)以下錯誤:

ERROR ITMS-90635: "Invalid Mach-O Format. The Mach-O in bundle "XXXX!.app/Frameworks/BRYXBanner.framework" isn’t consistent with the Mach-O in the main bundle. The main bundle Mach-O contains armv7(machine code) and arm64(machine code), while the nested bundle Mach-O contains armv7(bitcode) and arm64(bitcode). Verify that all of the targets for a platform have a consistent value for the ENABLE_BITCODE build setting." 
WARNING ITMS-90080: "The executable 'Payload/XXXX!.app/Frameworks/Bolts.framework' is not a Position Independent Executable. Please ensure that your build settings are configured to create PIE executables. For more information refer to Technical Q&A QA1788 - Building a Position Independent Executable in the iOS Developer Library."

stackoverflow 解決方法:http://stackoverflow.com/questions/37634627/upload-to-itunesconnect-failing

這是因?yàn)?Xcode 7 (或以上)默認(rèn)支持 bitcode,而你的項(xiàng)目關(guān)閉了bitcode(即在 【Build Settings】 中設(shè)置了 【Enable Bitcode】為 NO),需要在 Podfile中進(jìn)行額外配置:

post_install do |installer| 
  installer.pods_project.targets.each do |target| 
    target.build_configurations.each do |config| 
      config.build_settings['ENABLE_BITCODE'] = 'NO' 
    end 
  end 
end

升級Xcode8后報(bào)錯“target overrides the EMBEDDED_CONTENT_CONTAINS_SWIFTbuild setting”

升級 Xcode 8后,運(yùn)行 Pod install, 報(bào)以下錯誤:

[!] The X target overrides the `EMBEDDED_CONTENT_CONTAINS_SWIFT` build setting defined in `X’. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

[!] The `X` target overrides the `ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES` build setting defined in `X'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or
- Remove the build settings from the target.

stackoverflow 解決方法:http://stackoverflow.com/questions/39569743/errors-after-updating-to-xcode-8-no-such-module-and-target-overrides-the-em

步驟如下:

  • 找到 【Project/Targets】-->【Project Name】-->【Build Settings】
  • 搜索 "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES"
  • 右鍵 "debug",選擇 "other",輸入 $(inherited)
  • "release" 也做同樣的操作,然后重新 "pod install"

如下圖:


指定編譯版本

指定Target的 Swift 編譯版本為 3.0

post_install do |installer|
    installer.pods_project.targets.each do |target|
        target.build_configurations.each do |configuration|
            configuration.build_settings['SWIFT_VERSION'] = "3.0"
        end
    end
end

但如果是 Objective-C 跟 Swift 混編的項(xiàng)目, 想要引入 OC 的第三方庫的話, 還需要添加另一項(xiàng)參數(shù)

configuration.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = 'NO'
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容