iOS cocoapods升級及問題

安裝javascript

  1. 安裝Ruby
    CocoaPods基於Ruby語言開發而成,所以安裝CocoaPods前須要安裝Ruby環境。幸運的是Mac系統默認自帶Ruby環境,若是沒有請自行查找安裝。檢測是否安裝Ruby:
    $ gem -v2.0.14

安裝則會提示當前Ruby版本。gem介紹:gem是一個管理Ruby庫和程序的標準包,它經過Ruby Gem(如 http://rubygems.org/ )源來查找、安裝、升級和卸載軟件包,很是的便捷。java

  1. 更換gem源
    由於國內網絡的問題致使gem源間歇性中斷,緣由你懂的。所以咱們須要更換gem源,使用淘寶的gem源
    [https://ruby.taobao.org/.](https://ruby.taobao.org/%E3%80%82)
    第一步:移除默認的源
    gem sources --remove https://rubygems.org/

第二步:指定淘寶的源
gem sources -a https://ruby.taobao.org/ios

第三步:查看指定的源是否是淘寶源
$ gem sources -l *** CURRENT SOURCES *** https://ruby.taobao.org/git

若是是https://ruby.taobao.org/,則更換成功。github

  1. 安裝CocoaPods
    改爲淘寶源後執行如下命令進行安裝:
    sudo gem install cocoapods
    若是換成國內鏡像使用 gem install cocoapods 報錯:
    ERROR: While executing gem ... (Gem::DependencyError) Unable to resolve dependencies: cocoapods requires cocoapods-core (= 1.1.1), cocoapods-downloader (< 2.0, >= 1.1.2), cocoapods-trunk (< 2.0, >= 1.1.1), xcodeproj (< 2.0, >= 1.3.3)
    執行:
    sudo gem update --system && sudo gem install cocoapods

報錯:
ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/xcodeproj
執行:
sudo gem install -n /usr/local/bin cocoapods
安裝完成,輸入如下命令檢測是否安裝成功:
$ pod --version 1.1.1sql

cd到本身的項目目錄下
建立Podfile
vim Podfile
若是沒有建立Podfile
文件將沒法安裝, CocoaPods都不知道改安裝說明, 怎麼去安裝呢, 對吧.
[!] No `Podfile' found in the project directory.vim

輸入如下代碼(配置文件,須要添加的第三方):xcode

source 'https://github.com/CocoaPods/Specs.git' 
platform :ios, '8.0'
platform :ios, '8.0'

  inhibit_all_warnings! ruby

  target '工程名' do 網絡

  pod 'AFNetworking', '~> 2.6.0'

  end

而後保存退出
esc
:wq
執行
pod updateOR pod install
若是報錯:

[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `master`. You can try adding it manually in `~/.cocoapods/repos` or via `pod repo add`.

執行:
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer(xcode目錄)

紅色部分是個人Xcode的路徑,注意上面的代碼中的"--"和"select"之間有一個空格。

解決方法可使用一下代碼:

又產生的問題:通常這個時候會輸出--unalbe to get active developer directory

defaults write com.apple.finder _FXShowPosixPathInTitle -bool TRUE;killall Finder

這樣的話就能夠了,而後用你的Xcode的路徑代替上面的紅色的部分就能夠了。

問題描述

1:[!] The 'master' repo requires CocoaPods 1.0.0 - (currently using 0.39.0) Update CocoaPods, or checkout the appropriate tag in the repo.

問題緣由:沒有更新到最新cocoapods版本

  sudo gem install -n /usr/local/bin cocoapods –pre

  若是報錯或其餘問題

  sudo gem update --system && sudo gem install cocoapods

  出現報錯信息:
  ERROR: While executing gem ... (Errno::EPERM) Operation not permitted - /usr/bin/xcodeproj

  執行:
  sudo gem install -n /usr/local/bin cocoapods

  輸入如下命令檢測是否成功:
  pod --version 1.1.1

2:[!] The dependency `AFNetworking (~> 2.6.0)` is not used in any concrete target.

問題緣由:podfile升級到最新版本,pod裏的內容必須明確指出所用第三方庫的target

能夠修改Podfile文件的配置文件,讓它兼容不指定固定版本;且又不報錯

  platform :ios, '8.0'

  inhibit_all_warnings!

  target '工程名' do

  pod 'AFNetworking', '~> 2.6.0'

  end

3:Updating local specs repositories

遇到pod install或者pod update長時間卡在Updating local specs repositories

  • 常見的解決方式是跳過更新cocoapods的spec倉庫
  • pod install --verbose --no-repo-update
  • pod update --verbose --no-repo-update
  • 最好的辦法是
  • pod repo remove master
  • pod setup
  • pod install

4:[!]Your Podfile has had smart quotes sanitised. To avoid issues in the future, you should not use TextEdit for editing it. If you are not using TextEdit, you should turn off smart quotes in your editor of choice.

  不要使用文本編輯去編輯Podfile,使用Xcode編輯,或者使用終端敲命令去編輯。或者輸入格式錯誤,沒輸入運行版本:$platform:ios, ‘8.0‘

5:使用cocoapods導入第三方類庫後頭文件沒有代碼提示?

  選擇Target -> Build Settings 菜單,找到\」User Header Search Paths\」設置項,新增一個值"${SRCROOT}",而且選擇\」Recursive\」

6:[!]Unable to find a target named '  ';

  Podfile的工程文件和創建工程名不一致。名字改成一致便可

7:syntax error ,unexpected end-of-input,expecting keyword_end

  podfile寫法有問題,使用標準的podfile的寫法

  platform :ios, '8.0'

  inhibit_all_warnings!

  target '工程名' do

  pod 'AFNetworking', '~> 2.6.0'

  end

8: Analyzing dependencies

 [!]Could not automatically select an Xcode project . Specify one in your Podfile like 50 : xcodeproj ' path / to / Project . xcodeproj

  本身創建了一個空文件夾,沒有創建工程

  處理方法:刪除這個空工程,從新創建一個工程,再按照上面知識點講解一步步來便可。

9:pod 導入後出現"_OBJC_CLASS_$_xxx"

  target->build phases->link binary with libraries添加xxx.a

  若是不是pod導入的類庫,出現這種問題

  緣由:在建立類的時候沒有勾選"add to targets"

  target->build phases->compile sources 添加.h,.m文件

  或(建議用上面)
  在Build Setting 中的Other Linker Flags選項中加入$(OTHER_LDFLAGS)

10:Xcode - ld: library not found for -lPods

當新增長一個Target,而且pod install後,因爲建立項目是默認建立的Target的Build Phases中引用了舊的.a,例如libPods.a,當新增長Targget後,libPods.a已經變成了libPods-Test.a,而新增長的Target名字爲Second,依賴的.a爲libPods-Second.a。因此libPods.a此時已經再也不被引用,而且不會被生成,若是任何地方引用了就會報錯,解決辦法是出現問題的Target的Build Phases中刪除無用的.a引用,例如libPods.a

  target->build phases->link binary with libraries

11:pod 導入庫,找不到頭文件

  在TARGETS -> Search Paths -> User Header Search Paths 中 寫入 ${SRCROOT}再將後面參數改成recursive

12:若是要移除Cocoapods,則能夠:

  a. 刪除工程文件夾下的Podfile、Podfile.lock及Pods文件夾

  b. 刪除xcworkspace文件

  c. 使用xcodeproj文件打開工程,刪除Frameworks組下的Pods.xcconfig及libPods.a引用

  d. 在工程設置中的Build Phases下刪除Check Pods Manifest.lock及Copy Pods Resources

  不當心刪除pods.xcconfig,出現diff: /../Podfile.lock: No such file or directory

  sudo pod install一下就行了

  若是編譯的時候出現權限問題,對工程文件夾$sudo chmod 777 path-to-project-folder/*

  $sudo chown 777 path-to-project-folder/*

13:出現/Library/Ruby/Gems/2.0.0/gems/claide-0.8.1/lib/claide/command.rb:417:in `help!': [!] You cannot run CocoaPods as root. (CLAide::Help)

  從新打開一個終端,而後pod install,不要sudo pod install。

14:刪除CocoaPods版本,並安裝指定版本

  好比我原本安裝完CocoaPods 1.0.0版,但發現它實現跟先前仍是差異滿大的,決定降回0.39這個比較穩定版本;就能夠用命令先刪除本地的CocoaPods版本,再指定安裝特定版本;

  a 卸載 cocoapods(它會提示你要刪除本地哪一個版也能夠全刪)

  sudo gem uninstall cocoapods

  b 安裝 0.39版本

  sudo gem install -n /usr/local/bin cocoapods -v 0.39

15:更新 CocoaPods 或者之前手動添加過第三方SDK改用Cocopods,可能會出現如下的錯誤

錯誤1:
[!] The `Paopao [Debug]` target overrides the `PODS_ROOT` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation
- Use the `$(inherited)` flag, or - Remove the build settings from the target. [!] The `Paopao [Debug]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target. [!] The `Paopao [Release]` target overrides the `PODS_ROOT` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target. [!] The `Paopao [Release]` target overrides the `OTHER_LDFLAGS` build setting defined in `Pods/Target Support Files/Pods/Pods.release.xcconfig'. This can lead to problems with the CocoaPods installation - Use the `$(inherited)` flag, or - Remove the build settings from the target.

  產生此警告的緣由是項目 Target 中的一些設置,CocoaPods 也作了默認的設置,若是兩個設置結果不一致,就會形成問題。

  我想要使用 CocoaPods 中的設置,分別在個人項目中定義PODS_ROOTOther Linker Flags的地方,把他們的值用$(inherited)替換掉,進入終端,執行

pod update

  警告沒了

  一種簡單粗暴的方法:

  點擊項目文件 project.xcodeproj,右鍵顯示包內容,用文本編輯器打開project.pbxproj,刪除OTHER_LDFLAGS的地方,保存,pod update,警告沒了。。。。

16:

17:

相關文章
相關標籤/搜索