IOS開發常見問題

Unable to add a source with url https://github.com/CocoaPods/Specs.git named cocoapods.

錯誤場景

使用pod install下載依賴時,出現如下錯誤git

Cloning spec repo `cocoapods` from `https://github.com/CocoaPods/Specs.git`
[!] Unable to add a source with url `https://github.com/CocoaPods/Specs.git` named `cocoapods`.
You can try adding it manually in `/Users/ado/.cocoapods/repos` or via `pod repo add`.
複製代碼

解決方法

這是由於cocoapods的源碼在github,國內有時候訪問不是很穩定,因此咱們可使用國內鏡像源來解決。如下使用清華大學的鏡像github

$ cd ~/.cocoapods/repos 
$ pod repo remove master
$ git clone https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git master
複製代碼

而後在本身項目的podfile文件的第一行替換成如下代碼ruby

source 'https://mirrors.tuna.tsinghua.edu.cn/git/CocoaPods/Specs.git'
複製代碼

最後使用pod install便可。 參考:清華大學CoocoaPods鏡像bash

Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers

錯誤場景

朋友mac重裝了catalina 10.15.5,使用gem install cocoapods安裝cocoapods時出現如下錯誤。markdown

ERROR:  Error installing cocoapods:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.3/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20210711-1964-ncgneq.rb extconf.rb
checking for ffi.h... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
	--with-opt-dir
	--without-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/$(RUBY_BASE_NAME)
	--with-ffi_c-dir
	--without-ffi_c-dir
	--with-ffi_c-include
	--without-ffi_c-include=${ffi_c-dir}/include
	--with-ffi_c-lib
	--without-ffi_c-lib=${ffi_c-dir}/lib
	--enable-system-libffi
	--disable-system-libffi
	--with-libffi-config
	--without-libffi-config
	--with-pkg-config
	--without-pkg-config
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError) You have to install development tools first. from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `block in try_compile'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:534:in `with_werror' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:585:in `try_compile'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1109:in `block in have_header' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:959:in `block in checking_for'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block (2 levels) in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:361:in `block in postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:331:in `open'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:357:in `postpone' from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:958:in `checking_for'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1108:in `have_header' from extconf.rb:10:in `system_libffi_usable?'
	from extconf.rb:42:in `<main>' To see why this extension failed to compile, please check the mkmf.log which can be found here: /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.3/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.15.3 for inspection. Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.15.3/gem_make.out 複製代碼

解決方法

通過網上查詢發現是由於從10.15開始,不少目錄結構變了,這樣會致使編譯一些開發庫時致使找不到頭文件,而macOS_SDK_headers_for_macOS這個文件在10.15以後是沒有的,因此這裏咱們不使用系統自帶的ruby來安裝cocoapods便可。 使用rvm來安裝新版本的ruby,而後再安裝cocoapods。curl

安裝rvm

# 安裝
curl -sSL https://get.rvm.io | bash -s stable
# 刷新環境
source ~/.bash_profile
複製代碼

查詢rvm版本驗證是否安裝成功ide

rvm -v
複製代碼

安裝ruby

rvm install 2.7.4
複製代碼

查看ruby是否安裝成功oop

ruby -v
#下面出現版本號表明成功
複製代碼

安裝cocoapods

# 若是要指定安裝版本,最後加上-v 版本號
sudo gem install -n /usr/local/bin cocoapods -v 1.9.4
複製代碼

驗證是否安裝成功post

pod --version
#出現版本號表明成功
複製代碼

requirements_osx_brew_libs_install

錯誤場景

使用rvm安裝ruby時出現如下錯誤ui

Error running 'requirements_osx_brew_libs_install autoconf automake libtool pkg-config coreutils libyaml libksba readline zlib openssl@1.1',
please read /Users/ado/.rvm/log/1626011972_ruby-2.7.1/package_install_autoconf_automake_libtool_pkg-config_coreutils_libyaml_libksba_readline_zlib_openssl@1.1.log
Requirements installation failed with status: 1.
複製代碼

解決方法

打開上面報錯提示的log文件,發現是homebrew超過的問題。因此只須要將homebrew的源改爲國內鏡像源便可。這裏咱們使用中科大的鏡像

替換git

cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
複製代碼

替換core

cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
複製代碼

替換Bottles

# 使用echo $SHELL 查看本身的系統是bash仍是zsh
# bash的方式
echo 'export
HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile
# zsh的方式
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc
複製代碼

最後再使用rvm install 版本號 就能夠正常安裝ruby了。

相關文章
相關標籤/搜索