In our project we want to ensure that all developers are using the same version of CocoaPods by adding a version verification within the Podfile as a prerequisite check when a developer attempts to perform pod install or pod update.
Is it possible to achieve this from within the Podfile?
To do this you'll need to create a Gemfile, which is like a Podfile for RubyGems, which CocoaPods is distributed as. There is a guide to do this for CocoaPods here. Mainly you'll create a Gemfile with something like:
source 'https://rubygems.org'
gem 'cocoapods', '~> 0.38.2'
Then you can install your specified version with bundle install. This will install the same version on all developer's machines. After that you'll run bundle exec pod install to make sure that pod install is run by the version specified in your Gemfile (which may not be the case if the user has multiple version of CocoaPods installed).
Related
I just start a react-native project. However, this question had me for a day.
I tried all possible way to solve it. For example,
sudo gem uninstall cocoapods
rvm uninstall
brew install cocoapods
However, there is no luck for me.
I would like to point out that I can pod --version under other path but issue occur when I try to pod under my project path. I also tried to set rvm default version to 2.7.5 but issue still happen.
Also, I am not using Apple M1
Traceback (most recent call last):
4: from /Users/nicholas/.rvm/gems/ruby-2.7.5/bin/ruby_executable_hooks:22:in `<main>'
3: from /Users/nicholas/.rvm/gems/ruby-2.7.5/bin/ruby_executable_hooks:22:in `eval'
2: from /Users/nicholas/.rvm/gems/ruby-2.7.5/bin/pod:23:in `<main>'
1: from /Users/nicholas/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/rubygems.rb:296:in `activate_bin_path'
/Users/nicholas/.rvm/rubies/ruby-2.7.5/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': can't find gem cocoapods (>= 0.a) with executable pod (Gem::GemNotFoundException)
Try running bundle install in the root of your project. Then either go to ios and run pod install or use npx pod-install from the project root.
This issue is due to the difference in your default ruby version and ruby version specified in Gemfile . To install multiple ruby version you have to install rvm on your system and then install multiple rub versions. after install the ruby version specified in you gem file. you have to run the bundle install command . link
bundle install is a command we use to install the dependencies specified in your Gemfile.
Gemfile
Simply put, Gemfile is a format for describing gem dependencies for Ruby programs. Or you can say it contains the gems you need in this project.
After this you can install run npx pod-install or cd ios and pod install
Bundle install prior to pod install works.
To answer Bundle Install, what happens is, when generating react native project the configuration is set to default mac gem version. If you have updated gem version on your mac the project configuration could not pick the correct gem version. thats why it throws the can't find gem cocoapods.
by doing Bundle install, It will update the project config according to the mac gem version.
Remove cocoapods:
sudo gem uninstall cocoapods
Then instal again:
sudo gem install -n /usr/local/bin cocoapods
Background
A few years ago I installed cocoapods for a project I was working on. Since then I have not used it and now I need to update it to get Flutter working.
System
OS MacOS Mojave
Version 10.14.3
Question
I do not want to end up installing 2 different versions of cocoapods and cause myself a bunch of problems. I am trying to determine how I originally installed cocoapods so I can update it.
How can I determine how cocoapods was originally installed?
What I Tried
I can see cocoapods is installed because when I run,
pod --version the output is
1.3.1
When I run which cocoapods I get
cocoapods not found
When I run which pod I get
/usr/local/bin/pod
I checked that file and it is a cocoapods file installed by a ruby gem. This is what I see when I look at the file,
!/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
#
This file was generated by RubyGems.
#
The application 'cocoapods' is installed as part of a gem, and
this file is here to facilitate running it.
At this point I try and update it,
gem update cocoapods
I get,
Updating installed gems Nothing to update
When I run gem list I get a list of installed gems but pods nor cocoapods is in the list.
I also checked brew list and do not see it installed in there either. I can see evidence that it was installed as a gem but I do not understand why gem update cocoapods finds nothing to update.
Update
I broke down and went ahead and tried to install cocoapods as a gem since I already had the gem file in place.
gem install cocoapods
When I run gem list it shows that cocoapods was installed as version 1.6.1 as there are a bunch of new cocoapods files in my gem list.
When I run pod --version it still says 1.3.1.
I removed the pod file from /usr/local/bin and then ran pod --version again. At this point I get a command not found error.
After adding it back I can see the same output of the old version exists again. 1.3.1.
I tried removing the old pod file from /usr/local/bin and then gem install cocoapods. After doing so the pod command will not work but I can see that cocoapods is installed as a gem on my system.
Evidently there is a problem installing cocoapods on some newer MacOS systems due to the all of the permissions changes rolled out from Apple.
I saw a suggestion to install cocoapods on El Captain like this,
sudo gem install -n /usr/local/bin cocoapods
Which would explain why I have a rogue pod file inside of that directory.
Solution
I deleted the pod file out of my /usr/local/bin folder.
I installed cocoapods again using => sudo gem install -n /usr/local/bin cocoapods
Now when I run pod --version I get 1.6.1.
When using fastlane and cocoapods to build our iOS app I noticed that fastlane does not use the version of cocoapods that I have installed using
sudo gem install cocoapods
When running
pod --version
it returns the latest version which is of this moment
1.3.1
However, when running a build lane in fastlane it uses cocoapods version 1.2.1 for some reason.
I use this in my Fastfile to clean and pod install
cocoapods(
clean: true,
podfile: "Podfile"
)
Is there a way I can tel fastlane to use a specific version of cocoapods? Or use the version I have installed manually?
It's recommended to use a Gemfile:
It is recommended that you use a Gemfile to define your dependency on fastlane. This will clearly define the used fastlane version, and its dependencies, and will also speed up using fastlane.
Install bundler using sudo gem install bundler
Create a ./Gemfile in the root directory of your project with the content:
source "https://rubygems.org"
gem 'fastlane'
gem 'cocoapods'
Run [sudo] bundle update and add both the ./Gemfile and the ./Gemfile.lock to version control
Every time you run fastlane, use bundle exec fastlane [lane]
On your CI, add [sudo] bundle install as your first build step
To update fastlane, just run [sudo] bundle update
I had some problems with one version of the project. I've found this answer where someone suggest steps to remove all cocoapods-connected stuff from the machine and reinstall it. I did follow the steps:
$ 'pod --version'
0.36.1
$ gem list --local | grep cocoapods
cocoapods (0.39.0.rc.1, 0.38.2, 0.38.1, 0.37.2)
cocoapods-core (0.39.0.rc.1, 0.38.2, 0.38.1, 0.37.2)
cocoapods-downloader (0.9.3, 0.9.1)
cocoapods-plugins (0.4.2)
cocoapods-search (0.1.0)
cocoapods-stats (0.6.2, 0.5.3)
cocoapods-trunk (0.6.4, 0.6.1)
cocoapods-try (0.5.1, 0.4.5)
$ gem uninstall cocoapods // and all others from the list above
The problem is that when i again grep all cocoapods, the list was equal to upper one, nothing disappeared.
$ sudo gem uninstall cocoapods
Select gem to uninstall:
1. cocoapods-0.37.2
2. cocoapods-0.38.1
3. cocoapods-0.38.2
4. cocoapods-0.39.0.rc.1
5. All versions
> 5
$ pod --version
// here was the error command not found, so everything fine
$ sudo gem install cocoapods
Fetching: cocoapods-0.38.2.gem (100%)
Successfully installed cocoapods-0.38.2
Parsing documentation for cocoapods-0.38.2
Installing ri documentation for cocoapods-0.38.2
Done installing documentation for cocoapods after 2 seconds
1 gem installed
$ pod --version
Could not find proper version of cocoapods (0.36.1) in any of the sources
Run `bundle install` to install missing gems.
But why does it want me to install 0.36.1? Anyway, as it asked, I did:
$bundle install
Installing cocoapods-core 0.36.1
Installing cocoapods-downloader 0.8.1
Installing cocoapods-plugins 0.4.1
Installing cocoapods-trunk 0.6.0
Installing cocoapods-try 0.4.3
Installing cocoapods 0.36.1
// Many "using" dependencies
So now when I run:
$ pod --version
0.36.1
And I'm stuck :) Why can't I have newest release version? Maybe pod --version points to the newest version of cocoapods-core instead of only cocoapods, so everything is ok and I have the correct version?
Check if you use Gemfile and there is specified the version of
cocoapods.
You can use specific version by pod *version* action. For example: pod _1.5.0.beta.1_ update or pod _1.5.0.beta.1_ install
For anyone coming to this in an attempt to update cocoapods. After doing all of the above I wasn't able to get this resolved. I then headed to the resolved answer and being unwilling to remove RVM, I tried to resolve this issue another way.
I found that my issue did indeed lie in my Gemfile.
First, run
gem install cocoapods to ensure you have the latest version, or whatever specified version you were looking for downloaded.
Second, ensure your projects Gemfile hasn't specified a cocoapods version number and instead simply specifies it as:
gem "cocoapods"
If yours doesn't, change this and run bundle update to regenerate the Gemfile.lock file and your problem should be solved. If not, go ahead and delete the Gemfile.lock file altogether and then run bundle update. You can easily check to see which gem version will be loaded by opening the Gemfile.lock file and searching for cocoapods-core <version number here>
At this point, you can go into your project and run
pod setup
and then check the cocoapods version with
pod --version
and now FINALLY you are free to run
pod install
to replace the Podfile.lock file and get back to your happy dev life. Hope that helps someone and saves them from burning hours.
It seems something got messed up in my ruby version. I still have no idea what and why. I've managed to fix it via this solution: https://stackoverflow.com/a/25021772/849616. After it everything works correctly.
You might face this issue when it comes migrating to a higher Swift version. Assuming that you already have cocoapods installed, you probably need to run bundle update command (possibly with sudo).
For more details, you could check: https://guides.cocoapods.org/using/a-gemfile.html
Additionally, I'd suggest to do the following:
Install the latest Xcode version.
Clear derived data (not just clean project) in your project.
Run pod update command.
I have the same problem.
In my project, pod --version and gem which cocoapods always return diffrence version.
All I had to do is remove Gemfile.lock in my project and bundle install again. It removed the locked cocoapods version and install a new one.
Hope that helps some one here.
I ran pod install and I've got this error:
Could not find proper version of cocoapods (1.11.3) in any of the sources
and I ran:
bundle install
after that pod install worked properly
There are some answers saying using gem 'cocoapods', '0.33.1' or gem 'pod', '0.33.1
but this does not work.
ERROR: While executing gem ... (Gem::CommandLineError)
Unknown command cocoapods,
In one project I need to use 0.33.1, but 0.34.4 in another. How do I switch the cocoapods version quickly on command line? I don't want to use gem install or uninstall.
I am using rbenv with ruby version 2.0.0p0. Keep using rbenv is preferred but I can switch to rvm or pure ruby only if there is no other options.
Thanks.
You can do the following to use different versions:
pod _0.34.4_ install
or
pod _0.34.1_ install
This is precisely the purpose of Bundler
In one project, you specify this in the Gemfile:
gem 'cocoapods', '0.33.1'
along with all other gems.. and run bundle install to install them.
There are some other steps to make sure you load those gems from bundler, I'd read that site for the full documentation.
Rails projects have this already set up for you, but if this is a plain old ruby project, you have to wire it up yourself.
FYI I am using the following temp solution.
Since I am using rbenv, I install different versions of cocoapods under different version of ruby.
For example,
rbenv global 2.1.0
gem install cocoapods -v 0.34.4
rbenv global 2.0.0-p0
gem install cocoapods -v 0.33.1
When I work on different Xcode projects that requires different version of Cocoapods, I just switch ruby version on the fly, and Cocoapods version is switched accordingly.
As I mentioned these are xCode projects and we are not allowed to add gemfile or install gem in the project folder. So this works for me.