Error installing cocoapods error failed to build gem native extension

I am trying to install cocoapods to my MacBook Pro running with OSX 10.9.1 (new Mavericks) and after type gem install cocoapods I get the following error: Building native extensions. This could

First, check the version of Ruby you are using.

$ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
usr/bin/ruby

Now use Homebrew to install the latest Ruby.

$ brew install ruby
==> ruby
By default, binaries installed by gem will be placed into:
/usr/local/lib/ruby/gems/2.7.0/bin

You may want to add this to your PATH.

ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have ruby first in your PATH run:

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile

For compilers to find ruby you may need to set:

$ export LDFLAGS="-L/usr/local/opt/ruby/lib"
$ export CPPFLAGS="-I/usr/local/opt/ruby/include"

Follow the instructions to set PATH. Now you will go to see the installed Ruby. Make sure to replace the ‘xxx’ with your username.

$ echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/xxx/.bash_profile
$ echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile
$ echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile

$ source ~/.bash_profile

Finally, Make sure your PATH is in place.

$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ which ruby
/usr/local/opt/ruby/bin/ruby

You’re good to go! Make sure you install by specifying the save destination as follows.

$ sudo gem install -n /usr/local/bin cocoapods

I am getting the same error over and over again and I do not know why. I tried several ways to fix it, but nothing works.

Code Block sudo gem install cocoapods
Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
ERROR: Failed to build gem native extension.
    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /Library/Ruby/Site/2.6.0 -r ./siteconf20201202-2686-t7m7nb.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.13.1/mkmf.log
extconf failed, exit code 1
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.13.1/gem_make.out

Something might be wrong with Ruby, but I could not figure out what I should do to fix it.

Accepted Reply

Depending on some aspects this might work for you, if you don’t mind using the «SUDO» command:

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

Latest CocoaPods 1.10.0 won’t work.

Replies

I also had this exact same error when trying to install cocoapods on a new machine today. Not sure why? Any help would be awesome :)

Bump, exact same issue. MacOS 11.0, Ruby 2.6.0. Can’t find any fix anywhere.

Greetings!

Solution :-

1) Install homebrew via terminal.

2) After homebrew is successfully installed, type in the terminal ‘$ brew install cocoapods’

Done.

Hi,

this works for me.

sudo xcode-select —switch /Applications/Xcode-beta.app/Contents/Developer

explain solution
sudo xcode-select —switch <path to xcode>/Contents/Developer

=D

Depending on some aspects this might work for you, if you don’t mind using the «SUDO» command:

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

Latest CocoaPods 1.10.0 won’t work.

Thank you all ! With sudo gem install cocoapods it worked!

Same problem — XCode 12.3 on Mac OS 10.15.6.

Tried the CocoaPod mac app from the CocoaPods about page, which did have an option to install the command line tool, but it was version 1.1.x for some reason….

Brew install did the trick, and installed 1.10.0.

same issuse and i tried «brew install cocoapod «but it is intsalling version 1.5.2 and for my project to run properly it required version 1.9.0 and above
i even tried «sudo gem intsall cocoapods» and also tried modifying .bash_profile file method, none of them worked.. help me

am having the same problem , using: brew install cocoapod  , would install version 1.5 and I need version 1.10
even when I tried brew it installed version 1.5?????
every time I upgrade , it gives me same error msg:

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-21/2.6.0/ffi-1.15.4/mkmf.log

extconf failed, exit code 1

I solved this problem with using brew

You need to:

  1. install LATEST version of brew (https://treehouse.github.io/installation-guides/mac/homebrew)
  2. then use «brew uninstall cocoapods»
  3. install the latest version of cocoapods using «brew install cocoapods» (You must verify installed version with github version https://github.com/CocoaPods/CocoaPods/releases/tag/1.11.2, they must match)
  4. overwrite link to cocoapods with «brew link —overwrite cocoapods»
  5. check the version of cocoapods «pod —version»
  6. done, You have the latest version of cocoapods installed

Good that you showed the solution. I’ve been sitting on this problem for a long time and nothing helps. Your solution is good thanks

[!] Xcode — develop for iOS and macOS
  ✗ CocoaPods installed but not working.
    You appear to have CocoaPods installed but it is not working.
    This can happen if the version of Ruby that CocoaPods was installed with
    is different from the one being used to invoke it.
    This can usually be fixed by re-installing CocoaPods.
   To re-install see
   https://guides.cocoapods.org/using/getting-started.html#installation for
   instructions.

try installing cocoa pods using brew

$ brew install cocoapods

after it finishes downloading

$ pod —version

if it shows the version then cocoapods is installed

Содержание

  1. Failed to build gem native extension. Header file missing, #9602
  2. Comments
  3. Trouble with installing cocoapods
  4. Accepted Reply
  5. Replies

sudo gem install cocoapods

I’ve installed ruby 2.3.0 but I got the following error:

The text was updated successfully, but these errors were encountered:

Seems like a ruby issue on your system. Please ask in StackOverflow instead.

But wouldn’t it be helpful to at least mention the prerequisites in the docs?

This question has been asked on StackOverflow:

And on AskDifferent, the Apple-specific site on Stack Exchange:

I had the same problem on macOS Mojave 10.14.16

A few threads eventually lead me here which solved it for me:

It looks like CocoaPods 1.9.0, the latest version as of this writing, depends on a newer version of Ruby than 2.3.7. But macOS Mojave only includes Ruby 2.3.7, so you have a few different options.

  1. Upgrade to macOS Catalina and get Ruby 2.6.3
  2. Use Ruby Version Manager to install a newer version of Ruby
  3. Install an older version of CocoaPods
    sudo gem install cocoapods -v 1.8.4

I did 3
sudo gem install cocoapods -v 1.8.4

I was installing Flutter, now flutter doctor says «Xcode — develop for iOS and macOS» is OK.

I had a similar problem for macOS Catalina.
Here is what worked for me:

Hey, so I also had the same problem. This is probably happening because your computer has older version of ruby. So you need to first update your ruby. Mine worked for ruby 2.6.3 version.I got this solution from stackoverflow,

You need to first open terminal and put this code
curl -L https://get.rvm.io | bash -s stable

Then put this command
rvm install ruby-2.6

This would install the ruby for you if it hasn’ t been installed.After this just update the ruby to the new version
rvm use ruby-2.6.3

After this just make ruby 2.6.3 your default
rvm —default use 2.6.3

This would possibly fix your issue. You can now put the command
sudo gem install cocoapods
And the command
pod setup

Источник

Trouble with installing cocoapods

I am getting the same error over and over again and I do not know why. I tried several ways to fix it, but nothing works.

Something might be wrong with Ruby, but I could not figure out what I should do to fix it.

Accepted Reply

Depending on some aspects this might work for you, if you don’t mind using the «SUDO» command:

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

Latest CocoaPods 1.10.0 won’t work.

Having same issue with my mac, anyone please help.

I really don’t know how to thank you I spent 4 hours trying to solve this problem Thank you with all my heart

Man thanks. You are a lifesaver.

1) Install homebrew via terminal.

2) After homebrew is successfully installed, type in the terminal ‘$ brew install cocoapods’

Thank you my man, it solved my issues 🙂

Thanks. This worked for me

this works for me.

sudo xcode-select —switch /Applications/Xcode-beta.app/Contents/Developer

explain solution
sudo xcode-select —switch

Depending on some aspects this might work for you, if you don’t mind using the «SUDO» command:

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

Latest CocoaPods 1.10.0 won’t work.

Having same issue with my mac, anyone please help.

I really don’t know how to thank you I spent 4 hours trying to solve this problem Thank you with all my heart

Man thanks. You are a lifesaver.

Thank you all ! With sudo gem install cocoapods it worked!

Same problem — XCode 12.3 on Mac OS 10.15.6.

Tried the CocoaPod mac app from the CocoaPods about page, which did have an option to install the command line tool, but it was version 1.1.x for some reason.

Brew install did the trick, and installed 1.10.0.

how’d you get it to install 1.10.0, a detailed explanation would be desperately appreciated thank you. Ive been at it for 2/3 days straight on installing the latest version for my project

hai @ Me -Human has your problem been solved?

am having the same problem , using: brew install cocoapod , would install version 1.5 and I need version 1.10 even when I tried brew it installed version 1.5. every time I upgrade , it gives me same error msg:

Источник

Delightfully Nerdy

Solution worked for Mac Big Sur OS

NOTE : replace user_name — with your laptop user name

  1. Check the version of Ruby

    ruby -v

Also check the given path:
which ruby

  1. Use Homebrew to install the latest Ruby

    brew install ruby

Binaries installed by gem will be placed into:

/usr/local/lib/ruby/gems/2.7.0/bin

  1. Add this to your PATH.

If you need to have ruby first in your PATH run:

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/user_name/.bash_profile

  1. For compilers to find ruby you may need to set:

export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"

  1. Follow the below instructions to set PATH. Now you will go to see the installed Ruby.

echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> /Users/user_name/.bash_profile

echo 'export LDFLAGS="-L/usr/local/opt/ruby/lib"' >> ~/.bash_profile

echo 'export CPPFLAGS="-I/usr/local/opt/ruby/include"' >> ~/.bash_profile

source ~/.bash_profile

  1. Finally, Make sure your PATH is in place.

ruby -v

which ruby

  1. Make sure you install by specifying the save destination as follows.

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

Today when I configuring the Flutter development environment on Mac OS, according to flutter doctor command, I want to use the following command to install cocoapods:

sudo gem install cocoapods

But I got an error message:

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
	ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2/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 ./siteconf20210222-12879-1feqcae.rb extconf.rb
*** 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:546:in `block in try_link0'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/tmpdir.rb:93:in `mktmpdir'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:543:in `try_link0'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:570:in `try_link'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:672:in `try_ldflags'
	from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:1832:in `pkg_config'
	from extconf.rb:9: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.14.2/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/ffi-1.14.2 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/ffi-1.14.2/gem_make.out

I searched many places according to the keywords of this error message, and tried various methods such as upgrading the version and adjusting the path, but still no solution. Finally, it was mentioned in a forum discussion that «Recommended not to use the ruby that comes with Mac OS to install the package«.

So, I tried to switch the ruby version and reinstall it, this time it succeeded.


Solution

Install Ruby Version Manager (RVM):

curl -L https://get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm list known

Output:

# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.10]
[ruby-]2.5[.8]
[ruby-]2.6[.6]
[ruby-]2.7[.2]
[ruby-]3[.0.0]
ruby-head

In the examples I saw, the installation of 2.5.x and 2.6.x were successful.

Based on the higher the version the better, I chose 2.6.6 to install.

rvm install 2.6.6

After installation, you can use the following command to check ruby version, make sure that the current ruby version is you just installed.

ruby -v

Output:

ruby 2.6.6p146 (2020-03-31 revision 67876) [x86_64-darwin19]

Use the following command again:

sudo gem install cocoapods

Then you can install it normally.


References

  • https://rvm.io/
  • https://medium.com/%E5%BD%BC%E5%BE%97%E6%BD%98%E7%9A%84-swift-ios-app-%E9%96%8B%E7%99%BC%E6%95%99%E5%AE%A4/sudo-gem-install-cocoapods-show-failed-to-build-gem-native-extension-error-handling-9956a4e71385
  • https://stackoverflow.com/questions/20939568/error-error-installing-cocoapods-error-failed-to-build-gem-native-extension

Read More

  • [Solved] urllib.error.URLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

I have looked through a lot of these questions and none seem to apply. I am trying to install cocoapods and run pod init in my xcode project. When I run sudo gem install cocoa podsI get right the end and see this:

Building native extensions. This could take a while...
ERROR:  Error installing cocoapods:
ERROR: Failed to build gem native extension.

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20200314-453-8td9mi.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.12.2 for inspection.

And of course when I run pod init inside my Xcode project I get:

-bash: pod: command not found

mmmmmm's user avatar

mmmmmm

28.5k17 gold badges84 silver badges140 bronze badges

asked Mar 15, 2020 at 3:50

The Retro Gamer's user avatar

1

It looks like CocoaPods 1.9.0, the latest version as of this writing, depends on a newer version of Ruby than 2.3.7. But macOS Mojave only includes Ruby 2.3.7, so you have a few different options.

  • Upgrade to macOS Catalina and get Ruby 2.6.3
  • Use Ruby Version Manager to install a newer version of Ruby
  • Install an older version of CocoaPods
    sudo gem install cocoapods -v 1.8.4

Sources

Other people have trouble with CocoaPods 1.9.0 on Mojave. 1 2 3 4 5

Some people got it working by upgrading to Ruby 2.6 or newer. 1 2

answered Mar 15, 2020 at 5:09

Nic's user avatar

NicNic

3,3938 gold badges29 silver badges64 bronze badges

2

answered Jul 21, 2020 at 18:51

Ashiokai's user avatar

1

You must log in to answer this question.

Not the answer you’re looking for? Browse other questions tagged

.

Problem

When we install cocoapods in MacOS like this:

➜  ~ sudo gem install cocoapods

we get this error:

Fetching: concurrent-ruby-1.1.7.gem (100%)
Successfully installed concurrent-ruby-1.1.7
Fetching: i18n-0.9.5.gem (100%)
Successfully installed i18n-0.9.5
Fetching: thread_safe-0.3.6.gem (100%)
Successfully installed thread_safe-0.3.6
Fetching: tzinfo-1.2.7.gem (100%)
Successfully installed tzinfo-1.2.7
Fetching: activesupport-4.2.11.3.gem (100%)
Successfully installed activesupport-4.2.11.3
Fetching: nap-1.1.0.gem (100%)
Successfully installed nap-1.1.0
Fetching: fuzzy_match-2.0.4.gem (100%)
Successfully installed fuzzy_match-2.0.4
Fetching: httpclient-2.8.3.gem (100%)
Successfully installed httpclient-2.8.3
Fetching: algoliasearch-1.27.4.gem (100%)
Successfully installed algoliasearch-1.27.4
Fetching: ffi-1.13.1.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing cocoapods:
  ERROR: Failed to build gem native extension.

    current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20201011-18064-1amwcon.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /Library/Ruby/Gems/2.3.0/gems/ffi-1.13.1 for inspection.
Results logged to /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.13.1/gem_make.out

When we look at the gem_make.out , we get this:

➜  ~ cat /Library/Ruby/Gems/2.3.0/extensions/universal-darwin-18/2.3.0/ffi-1.13.1/gem_make.out
current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -r ./siteconf20201011-18064-1amwcon.rb extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/include/ruby.h

extconf failed, exit code 1

Environment

  • MacOS 10.14
  • Ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
  • Gem 2.5.2.3

Reason

According to this post, the reason is:

The issue is that Xcode 11 ships the macOS 10.15 SDK which includes headers for ruby2.6, but not for macOS 10.14’s ruby2.3.

Let check the ruby config:

➜  ~ ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

➜  ~ ls -l /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0
ls: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0: No such file or directory

You can see that , the output contains a directory(MacOSX10.15) that does not even exist!

Solution

We should fix this issue by updating the ruby config to the correct path:

➜  ~ sudo xcode-select --switch /Library/Developer/CommandLineTools
➜  ~ ruby -rrbconfig -e 'puts RbConfig::CONFIG["rubyhdrdir"]'
/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0

Let’s try again:

➜  ~ sudo gem install cocoapods
Building native extensions.  This could take a while...
Successfully installed ffi-1.13.1
Fetching: ethon-0.12.0.gem (100%)
Successfully installed ethon-0.12.0
Fetching: typhoeus-1.4.0.gem (100%)
Successfully installed typhoeus-1.4.0
Fetching: netrc-0.11.0.gem (100%)
Successfully installed netrc-0.11.0
Fetching: cocoapods-core-1.9.3.gem (100%)
Successfully installed cocoapods-core-1.9.3
Fetching: claide-1.0.3.gem (100%)
Successfully installed claide-1.0.3
Fetching: cocoapods-deintegrate-1.0.4.gem (100%)
Successfully installed cocoapods-deintegrate-1.0.4
Fetching: cocoapods-downloader-1.4.0.gem (100%)
Successfully installed cocoapods-downloader-1.4.0
Fetching: cocoapods-plugins-1.0.0.gem (100%)
Successfully installed cocoapods-plugins-1.0.0
Fetching: cocoapods-search-1.0.0.gem (100%)
Successfully installed cocoapods-search-1.0.0
Fetching: cocoapods-stats-1.1.0.gem (100%)
Successfully installed cocoapods-stats-1.1.0
Fetching: cocoapods-trunk-1.5.0.gem (100%)
Successfully installed cocoapods-trunk-1.5.0
Fetching: cocoapods-try-1.2.0.gem (100%)
Successfully installed cocoapods-try-1.2.0
Fetching: molinillo-0.6.6.gem (100%)
Successfully installed molinillo-0.6.6
Fetching: atomos-0.1.3.gem (100%)
Successfully installed atomos-0.1.3
Fetching: CFPropertyList-3.0.2.gem (100%)
Successfully installed CFPropertyList-3.0.2
Fetching: colored2-3.1.2.gem (100%)
Successfully installed colored2-3.1.2
Fetching: nanaimo-0.3.0.gem (100%)
Successfully installed nanaimo-0.3.0
Fetching: xcodeproj-1.19.0.gem (100%)
Successfully installed xcodeproj-1.19.0
Fetching: escape-0.0.4.gem (100%)
Successfully installed escape-0.0.4
Fetching: fourflusher-2.3.1.gem (100%)
Successfully installed fourflusher-2.3.1
Fetching: gh_inspector-1.1.3.gem (100%)
Successfully installed gh_inspector-1.1.3
Fetching: ruby-macho-1.4.0.gem (100%)
Successfully installed ruby-macho-1.4.0
Fetching: cocoapods-1.9.3.gem (100%)
Successfully installed cocoapods-1.9.3
Parsing documentation for ffi-1.13.1
Installing ri documentation for ffi-1.13.1
Parsing documentation for ethon-0.12.0
Installing ri documentation for ethon-0.12.0
Parsing documentation for typhoeus-1.4.0
Installing ri documentation for typhoeus-1.4.0
Parsing documentation for netrc-0.11.0
Installing ri documentation for netrc-0.11.0
Parsing documentation for cocoapods-core-1.9.3
Installing ri documentation for cocoapods-core-1.9.3
Parsing documentation for claide-1.0.3
Installing ri documentation for claide-1.0.3
Parsing documentation for cocoapods-deintegrate-1.0.4
Installing ri documentation for cocoapods-deintegrate-1.0.4
Parsing documentation for cocoapods-downloader-1.4.0
Installing ri documentation for cocoapods-downloader-1.4.0
Parsing documentation for cocoapods-plugins-1.0.0
Installing ri documentation for cocoapods-plugins-1.0.0
Parsing documentation for cocoapods-search-1.0.0
Installing ri documentation for cocoapods-search-1.0.0
Parsing documentation for cocoapods-stats-1.1.0
Installing ri documentation for cocoapods-stats-1.1.0
Parsing documentation for cocoapods-trunk-1.5.0
Installing ri documentation for cocoapods-trunk-1.5.0
Parsing documentation for cocoapods-try-1.2.0
Installing ri documentation for cocoapods-try-1.2.0
Parsing documentation for molinillo-0.6.6
Installing ri documentation for molinillo-0.6.6
Parsing documentation for atomos-0.1.3
Installing ri documentation for atomos-0.1.3
Parsing documentation for CFPropertyList-3.0.2
Installing ri documentation for CFPropertyList-3.0.2
Parsing documentation for colored2-3.1.2
Installing ri documentation for colored2-3.1.2
Parsing documentation for nanaimo-0.3.0
Installing ri documentation for nanaimo-0.3.0
Parsing documentation for xcodeproj-1.19.0
Installing ri documentation for xcodeproj-1.19.0
Parsing documentation for escape-0.0.4
Installing ri documentation for escape-0.0.4
Parsing documentation for fourflusher-2.3.1
Installing ri documentation for fourflusher-2.3.1
Parsing documentation for gh_inspector-1.1.3
Installing ri documentation for gh_inspector-1.1.3
Parsing documentation for ruby-macho-1.4.0
Installing ri documentation for ruby-macho-1.4.0
Parsing documentation for cocoapods-1.9.3
Installing ri documentation for cocoapods-1.9.3
Done installing documentation for ffi, ethon, typhoeus, netrc, cocoapods-core, claide, cocoapods-deintegrate, cocoapods-downloader, cocoapods-plugins, cocoapods-search, cocoapods-stats, cocoapods-trunk, cocoapods-try, molinillo, atomos, CFPropertyList, colored2, nanaimo, xcodeproj, escape, fourflusher, gh_inspector, ruby-macho, cocoapods after 43 seconds
24 gems installed
➜  ~

The last step

Since we changed the xcode settings, we should restore it:

➜  ~ sudo xcode-select --switch /Applications/Xcode.app

xcode-select is a command-line utility on OS X that facilitates switching between different sets of command line developer tools provided by Apple. Its primary function is to be a “master switch” for the actual paths resolved when invoking the commands for tools like make , xcodebuild , otool , etc

Ok, everything is done.

If you are using Unity to build your iOS projects and use SDK’s like Firebase, Facebook etc. which require CocoaPods, then these steps enlisted below should help you run a smooth and successful build.

Even if you are not using Unity and just using Xcode project, these steps should ensure that the pods get installed in your project successfully.

Once everything is setup, the builds usually almost always run successfully and rarely give problems. It is mostly during the first build or sometimes after an OS update or after a hard disk change or moving to a new machine, that problems creep up and the Unity build fails with the message – iOS framework addition failed due to a Cocoapods installation failure. This will will likely result in an nonfunctional Xcode project.“. It is a long error message in the Console which would probably state how even the “pod repo update” was attempted and it failed as well.

For the people who aren’t aware how Pods work and not familiar with the Xcode CocoaPods workflow, this error is very hard to decipher and fix.

If you have encountered this error, follow the steps below to fix it and setup CocoaPods correctly.

The setup used for the purpose of this writeup:

MacOS Catalina (10.15.6)

Unity 2018.4.22f1

Xcode 11.4.1

CocoaPods 1.9.1 

1) Install Xcode. 

Pretty self explanatory and in all probability you should have done this step already. Xcode can be installed from the Mac AppStore or by downloading a xip file from the apple developer site.


2) Sudo xcode-select

Now we have to ensure that our system knows where our Xcode is and specifically where the developer tools which come bundled with it are installed.

Open Terminal on your Mac and run the following command.

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

Please note that the path to Xcode on your machine may vary. The path listed above is the default location of Xcode. You may have installed or moved Xcode to a new location. In that case, please run the command with the appropriate path.

Sometimes, just this magic command can make your build run fine. If it doesn’t, follow the next steps to install and correctly setup CocoaPods on your system.


3) CocoaPods installation and setup.

If your build is failing, the most likely cause is that CocoaPods is not installed and setup properly. So follow the steps below and by the end of it, CocoaPods would be installed successfully on your system.

First lets remove any previous installations so that we can make a fresh start. Open a Terminal and run the command below. If there was a previous installation (or more than one installations) this will remove them. Type “y” and press “Enter/Return” on any prompts that this command makes.

sudo gem uninstall cocoapods

Once you have uninstalled the previous version (or if no previous version exists) proceed to install cocoapods. Run the following command on the Terminal.

sudo gem install cocoapods

Let the process complete successfully. This should install the latest version of CocoaPods on your system.

But the installation process isn’t complete. CocoaPods is basically a repository of frameworks and their dependencies. You just have to specify which “pods” you want in your project in a podfile and it installs them. But in order for it to work, the entire repository needs to be on your system in a specific folder. There are several ways to do that. The first time you run a pod install, it will download the repository before proceeding. In older versions of CocoaPods, you can run pod setup and it should do the job (since version 1.8.0, pod setup does nothing!). Or in some cases pod repo update might work. 

But I am going to list the method that I use which works for me every time.

First we need to create a folder. Go to your user folder using Finder Explorer. Look for a folder name .cocoapods. (It is a hidden folder since the name starts with a dot). If you can’t see the folder, press Command+Shift+. to reveal the hidden folders. If the folder doesn’t exist, then create one with the name. Open the folder and look for a folder named repos. If the folder doesn’t exist, create one by that name. Open the repos folder. If there is a master folder inside it, then delete it. We are going to recreate it. Your folder structure should look like this :

Once you have got this open the terminal and run the below commands one by one.

cd ~/.cocoapods/repos

git clone --depth 1 https://github.com/CocoaPods/Specs.git master

pod repo update

The git command should take a few minutes to complete as it downloads the repository to your system. Ensure all the commands listed above are completed successfully. Your folder structure should look like this.

Voila! Now you have completed the installation correctly. Go back to Unity and build for iOS again. And this time the build should succeed without any errors!


4) Use .xcworkspace file instead of .xcodeproj

If you are new to using Pods, then you probably won’t even be aware of this. If you are experienced, there is still a chance that you might forget this.

Always, use the .xcworkspace file to open your project in Xcode and not the .xcodeproj which you are probably used to.

Once the unity build process completes and the pods are installed successfully, notice that the generated Xcode project now has a .xcworkspace file alongside the usual .xcodeproj file. Use the .xcworkspace file to open you project in Xcode. Using the .xcodeproj file to open the project will lead to errors when building the Xcode project.


4a) There is no .xcworkspace file in my Xcode project!

Relax. This may not be a problem. Unity also has the ability to load pods from .xcodeproj file as well. The External Dependency Manager used by Unity to manage pods has the option to add pods to either to the workspace or the project file as shown in the image below. Check which setting you are using by going to the following location in Unity.

Assets -> External Dependency Manager -> iOS Resolver -> Settings 

If there is no workspace file in your project, try building the project using the .xcodeproj file. If it doesn’t work, try changing the iOS Resolver Setting and generate a .xcworkspace file.


5) Keep CocoaPods updated.

Everything might work correctly for some time and then suddenly you might face the pod installation error again. This might be because the repo could not be updated due to some error. Try running the ‘pod repo update’ command manually again and see if it helps.

Also it might be possible that your CocoaPods version is outdated and one or more of your pods require a higher version of CocoaPods. In that case, just run the below command (same command which was used for installing) and it will update you CocoaPods to the latest version. 

sudo gem install cocoapods




There is a strange bug currently if you are using Unity + Firebase where the Xcode build will fail with error –

Unable to read Google Service plist at path….

This error is surprisingly being caused because of spaces in build folder name! To fix this error, just rename your build folder without any spaces and then run the build again. It should run successfully now.

Refer to below links:

https://github.com/firebase/quickstart-unity/issues/557
https://github.com/firebase/quickstart-unity/issues/714


Some parting info on CocoaPods

There’s a lot of information on CocoaPods out on the internet, some old some new. A lot of questions being answered on StackOverflow. If you have been going through all the material, it can cause quite a lot of confusion. Especially with the new versions of CocoaPods not requiring the master repository on your system. Let me help you out with that.

As of CocoaPods version 1.8.0, there is no mandatory requirement for the master repository on your system. However, this also requires a change in the projects podfile to change the source of download. When testing with Unity 2018.4.22f1, I found the podfile still tries to download from the master repository and hence the master repo is required on the system. If the repo is not present, the Unity build process will try to download and install the repo which may fail due to network issues or some other error and will cause the build to fail. So it is better to have the master repository for now. In the future, when the new methodology is stable and becomes the norm, we probably won’t need the master repository.

When running into issues, a lot of old answers on internet can point you to “pod setup”  to solve the problem. Let me reiterate that as of version 1.8.0, this command does nothing and just prints a completed message. Hence don’t rely on it.

“pod repo update” command can be run to keep the master repo updated but it requires the master repository correctly configured to work. It especially requires the .git folder inside the master folder to be configured correctly. This command can be run on Terminal from any folder.

“pod install” command is used to install the pods in your project. It will also download and install the master repository if it is not present. This command can only be run from a folder which has a valid podfile.


Hopefully you won’t run into any issues if you follow the above mentioned steps correctly and won’t need any additional help.

I am no expert on CocoaPods. But I have had to fiddle around to get my project to build with Google Firebase SDK and Facebook SDK. Hopefully this writeup will help any one else coming across the same problems.

Понравилась статья? Поделить с друзьями:
  • Error installation failed lsb package may not be installed
  • Error installation failed cannot re use a name that is still in use
  • Error installation did not succeed the application could not be installed retry
  • Error install motioninjoy driver fail error code 0x2
  • Error install failure 0x80070643