cocoapods安裝步驟及常見問題解決

1.檢查ruby源:gem sources -l;

    如果是

    *** CURRENT SOURCES ***

 https://rubygems.org/

  當然這個源在牆內是訪問不到的。因此我們需要尋找一個可以在國內訪問到的鏡像。


2.刪除原來的ruby源:gem sources --removehttps://rubygems.org/

   注:如果出現source https://rubygems.org not present in cache情況,嘗試用

         sudo gem sources -rhttps://rubygems.org/命令刪除


3.添加可用的鏡像源:gem sources -ahttps://gems.ruby-china.org

   注:如果出現ERROR:  While executing gem ... (Errno::EACCES)

           Permission denied - /Users/Apple/.gemrc情況,嘗試用

           sudo gem sources -ahttps://gems.ruby-china.org命令添加

    使用gem sources -l查看是否添加成功,如果打印出

     *** CURRENT SOURCES ***

    https://gems.ruby-china.org

   表示添加成功


4.下載和安裝CocoaPods: sudo gem install -n /usr/local/bin cocoapods

     注:如果出現Fetching: activesupport-5.0.0.1.gem (100%)

            ERROR:  While executing gem ... (Gem::FilePermissionError)

            You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.

          則用sudo gem install cocoapods命令:

          如果出現ERROR:  Error installing cocoapods:

activesupport requires Ruby version >= 2.2.2.情況,則調用

          curl -L get.rvm.io | bash -s stable命令安裝RVM baby版本管理器,

         //________等安裝完成 出現下面這行提示以下___________

      In case of problems: https://rvm.io/helpandhttps://twitter.com/rvm_io

       執行:$source ~/.bashrc  

                  $source ~/.bash_profile 

      測試是否安裝正常:$rvm -v 

      //________提示以下___________

      rvm 1.27.0 (latest) by Wayne E. Seguin, Michal Papis[https://rvm.io/]

      用RVM升級Ruby查看當前ruby版本:$ruby -v 

                                                                       $rvm list known

     安裝ruby 2.2.2 執行:rvm install 2.2,如果有提示:Ruby was built without documentation, to build it run: rvm docs generate-ri則調用Apple$ rvm docs generate-ri命        令,最後調用sudo gem install cocoapods再次安裝cocoapods


5、更新Podspec索引文件,創建本地索引庫(這裏要多等一會兒)

     pod setup

      如果更新成功,就不用執行6和7步驟

6.安裝成功後,Apple$ pod search Afnet測試,如果出現Setting up CocoaPods master repo卡住現象:

        解決方法:Apple$ pod repo remove master

                            Apple$ git clone https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master

                            Apple$ pod repo update

7.搜索庫文件:Apple$ pod search Afnet

      如果出現[!] Unable to find a pod with name, author, summary, or descriptionmatching `Afnet`情況:

         解決方法:Apple$ pod setup 此方法如果不行

                             則執行Apple$ rm ~/Library/Caches/CocoaPods/search_index.json命令


8、進入項目目錄

     cd ~

9、創建Podfile文件

     touch Podfile

10.打開工程文件,導入pod:

    Apple$ cd /Users/Apple/Documents/xmTest/Test

    Apple$ vim Podfile:格式如下

                platform:ios, '7.0'

                target 'Test' do//其中Test爲項目名

               pod 'AFNetworking', '~> 3.1.0'

               end


11.安裝:Apple$ pod install


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章